Skip to content

Commit

Permalink
swtpm_setup: Move gmalloc after block that may return NULL on failure
Browse files Browse the repository at this point in the history
To avoid a memory leak, move the gmalloc after a block that may
return NULL on failure.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
  • Loading branch information
stefanberger committed Oct 5, 2021
1 parent b63a3e4 commit 2e3745d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/swtpm_setup/swtpm_backend_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ static void *parse_file_state(const gchar* uri) {
uri += 7;
}

ret = g_malloc(sizeof(struct file_state));
ret->path = g_strdup(uri);

stat_ret = stat(uri, &statbuf);
if (stat_ret != 0) {
noent = errno == ENOENT;
Expand All @@ -43,6 +40,9 @@ static void *parse_file_state(const gchar* uri) {
return NULL;
}
}

ret = g_malloc(sizeof(struct file_state));
ret->path = g_strdup(uri);
ret->is_blockdev = noent ? false : S_ISBLK(statbuf.st_mode);

return (void*)ret;
Expand Down

0 comments on commit 2e3745d

Please sign in to comment.