mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-18 22:30:07 +01:00
Fix leaked fd gcc analyzer warning.
These are actually false positives (fd 0 is always open as stdin), but code is even more readable with this fix.
This commit is contained in:
@@ -164,6 +164,7 @@ int tools_read_json_file(const char *file, char **json, size_t *json_size, bool
|
||||
ssize_t ret;
|
||||
int fd, block, r;
|
||||
void *buf = NULL;
|
||||
bool close_fd = false;
|
||||
|
||||
block = tools_signals_blocked();
|
||||
if (block)
|
||||
@@ -180,6 +181,7 @@ int tools_read_json_file(const char *file, char **json, size_t *json_size, bool
|
||||
r = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
close_fd = true;
|
||||
}
|
||||
|
||||
buf = malloc(LUKS2_MAX_MDA_SIZE);
|
||||
@@ -211,7 +213,7 @@ int tools_read_json_file(const char *file, char **json, size_t *json_size, bool
|
||||
out:
|
||||
if (block && !quit)
|
||||
set_int_block(1);
|
||||
if (fd >= 0 && fd != STDIN_FILENO)
|
||||
if (close_fd)
|
||||
close(fd);
|
||||
if (r && buf) {
|
||||
memset(buf, 0, LUKS2_MAX_MDA_SIZE);
|
||||
|
||||
Reference in New Issue
Block a user