]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: Fix memory leak in testCompareXMLToArgvFiles
authorJohn Ferlan <jferlan@redhat.com>
Fri, 8 Feb 2019 15:43:23 +0000 (10:43 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 12 Feb 2019 18:11:36 +0000 (13:11 -0500)
Only one path will consume the @def; otherwise, we need to free it.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tests/storagepoolxml2argvtest.c

index 288b81af1de35ea4cd302de2ef77ff764e33b267..b7e32064af3ed37ef7492121f266a98acc72f190 100644 (file)
@@ -25,29 +25,33 @@ testCompareXMLToArgvFiles(bool shouldFail,
     int ret = -1;
     virStoragePoolDefPtr def = NULL;
     virStoragePoolObjPtr pool = NULL;
+    const char *defTypeStr;
     VIR_AUTOFREE(char *) actualCmdline = NULL;
     VIR_AUTOFREE(char *) src = NULL;
     VIR_AUTOPTR(virCommand) cmd = NULL;
 
     if (!(def = virStoragePoolDefParseFile(poolxml)))
         goto cleanup;
+    defTypeStr = virStoragePoolTypeToString(def->type);
 
     switch ((virStoragePoolType)def->type) {
     case VIR_STORAGE_POOL_FS:
     case VIR_STORAGE_POOL_NETFS:
         if (!(pool = virStoragePoolObjNew())) {
-            VIR_TEST_DEBUG("pool type %d alloc pool obj fails\n", def->type);
+            VIR_TEST_DEBUG("pool type '%s' alloc pool obj fails\n", defTypeStr);
             virStoragePoolDefFree(def);
             goto cleanup;
         }
         virStoragePoolObjSetDef(pool, def);
 
         if (!(src = virStorageBackendFileSystemGetPoolSource(pool))) {
-            VIR_TEST_DEBUG("pool type %d has no pool source\n", def->type);
+            VIR_TEST_DEBUG("pool type '%s' has no pool source\n", defTypeStr);
+            def = NULL;
             goto cleanup;
         }
 
         cmd = virStorageBackendFileSystemMountCmd(MOUNT, def, src);
+        def = NULL;
         break;
 
     case VIR_STORAGE_POOL_LOGICAL:
@@ -67,12 +71,12 @@ testCompareXMLToArgvFiles(bool shouldFail,
     case VIR_STORAGE_POOL_VSTORAGE:
     case VIR_STORAGE_POOL_LAST:
     default:
-        VIR_TEST_DEBUG("pool type %d has no xml2argv test\n", def->type);
+        VIR_TEST_DEBUG("pool type '%s' has no xml2argv test\n", defTypeStr);
         goto cleanup;
     };
 
     if (!(actualCmdline = virCommandToString(cmd, false))) {
-        VIR_TEST_DEBUG("pool type %d failed to get commandline\n", def->type);
+        VIR_TEST_DEBUG("pool type '%s' failed to get commandline\n", defTypeStr);
         goto cleanup;
     }
 
@@ -83,6 +87,7 @@ testCompareXMLToArgvFiles(bool shouldFail,
     ret = 0;
 
  cleanup:
+    virStoragePoolDefFree(def);
     virStoragePoolObjEndAPI(&pool);
     if (shouldFail) {
         virResetLastError();