mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00:00
tests: Fix memory leak in testCompareXMLToArgvFiles
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>
This commit is contained in:
parent
180f3207ae
commit
bc096fc4a2
@ -25,29 +25,33 @@ testCompareXMLToArgvFiles(bool shouldFail,
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
virStoragePoolDefPtr def = NULL;
|
virStoragePoolDefPtr def = NULL;
|
||||||
virStoragePoolObjPtr pool = NULL;
|
virStoragePoolObjPtr pool = NULL;
|
||||||
|
const char *defTypeStr;
|
||||||
VIR_AUTOFREE(char *) actualCmdline = NULL;
|
VIR_AUTOFREE(char *) actualCmdline = NULL;
|
||||||
VIR_AUTOFREE(char *) src = NULL;
|
VIR_AUTOFREE(char *) src = NULL;
|
||||||
VIR_AUTOPTR(virCommand) cmd = NULL;
|
VIR_AUTOPTR(virCommand) cmd = NULL;
|
||||||
|
|
||||||
if (!(def = virStoragePoolDefParseFile(poolxml)))
|
if (!(def = virStoragePoolDefParseFile(poolxml)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
defTypeStr = virStoragePoolTypeToString(def->type);
|
||||||
|
|
||||||
switch ((virStoragePoolType)def->type) {
|
switch ((virStoragePoolType)def->type) {
|
||||||
case VIR_STORAGE_POOL_FS:
|
case VIR_STORAGE_POOL_FS:
|
||||||
case VIR_STORAGE_POOL_NETFS:
|
case VIR_STORAGE_POOL_NETFS:
|
||||||
if (!(pool = virStoragePoolObjNew())) {
|
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);
|
virStoragePoolDefFree(def);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
virStoragePoolObjSetDef(pool, def);
|
virStoragePoolObjSetDef(pool, def);
|
||||||
|
|
||||||
if (!(src = virStorageBackendFileSystemGetPoolSource(pool))) {
|
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;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = virStorageBackendFileSystemMountCmd(MOUNT, def, src);
|
cmd = virStorageBackendFileSystemMountCmd(MOUNT, def, src);
|
||||||
|
def = NULL;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_STORAGE_POOL_LOGICAL:
|
case VIR_STORAGE_POOL_LOGICAL:
|
||||||
@ -67,12 +71,12 @@ testCompareXMLToArgvFiles(bool shouldFail,
|
|||||||
case VIR_STORAGE_POOL_VSTORAGE:
|
case VIR_STORAGE_POOL_VSTORAGE:
|
||||||
case VIR_STORAGE_POOL_LAST:
|
case VIR_STORAGE_POOL_LAST:
|
||||||
default:
|
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;
|
goto cleanup;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!(actualCmdline = virCommandToString(cmd, false))) {
|
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;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,6 +87,7 @@ testCompareXMLToArgvFiles(bool shouldFail,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
virStoragePoolDefFree(def);
|
||||||
virStoragePoolObjEndAPI(&pool);
|
virStoragePoolObjEndAPI(&pool);
|
||||||
if (shouldFail) {
|
if (shouldFail) {
|
||||||
virResetLastError();
|
virResetLastError();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user