From 2e3745db08ca827f715752aa5109c6760b2e1bd0 Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Tue, 5 Oct 2021 16:22:25 -0400 Subject: [PATCH] swtpm_setup: Move gmalloc after block that may return NULL on failure To avoid a memory leak, move the gmalloc after a block that may return NULL on failure. Signed-off-by: Stefan Berger --- src/swtpm_setup/swtpm_backend_file.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/swtpm_setup/swtpm_backend_file.c b/src/swtpm_setup/swtpm_backend_file.c index c6b6b1e2..a0d0f4d2 100644 --- a/src/swtpm_setup/swtpm_backend_file.c +++ b/src/swtpm_setup/swtpm_backend_file.c @@ -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; @@ -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;