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 <stefanb@linux.ibm.com>
diff --git a/src/swtpm_setup/swtpm_backend_file.c b/src/swtpm_setup/swtpm_backend_file.c
index c6b6b1e..a0d0f4d 100644
--- a/src/swtpm_setup/swtpm_backend_file.c
+++ b/src/swtpm_setup/swtpm_backend_file.c
@@ -32,9 +32,6 @@
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 @@
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;