]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: Fix memory leak in mymain
authorJohn Ferlan <jferlan@redhat.com>
Wed, 7 Aug 2019 13:57:46 +0000 (09:57 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Wed, 7 Aug 2019 15:44:17 +0000 (11:44 -0400)
Commit d2899a648 added a new exit path, but didn't free @fakerootdir.
Let's just use VIR_AUTOFREE instead to make life easier.

Found by Coverity

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
tests/virhostdevtest.c

index 7d15a87797dd80f670ce88c78897c6175a124f3a..20984f34428cf3dae55a7efb853566dfa44612ad 100644 (file)
@@ -556,7 +556,7 @@ static int
 mymain(void)
 {
     int ret = 0;
-    char *fakerootdir;
+    VIR_AUTOFREE(char *) fakerootdir = NULL;
 
     if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) {
         fprintf(stderr, "Out of memory\n");
@@ -594,8 +594,6 @@ mymain(void)
     if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
         virFileDeleteTree(fakerootdir);
 
-    VIR_FREE(fakerootdir);
-
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }