testCompareXMLToArgvValidateSchema: Construct @vm from scratch

Currently, the @vm is passed in as an argument and
testCompareXMLToArgvCreateArgs() is called over it which means
under the hood qemuProcessPrepareDomain() is called. But at the
point where ValidateSchema() is called, the domain object is
already 'prepared', i.e. all device aliases are assigned and so
on. But our code is not prepared to 'prepare' a domain twice - it
simply overwrites all the pointers leading to a memory leak.

Fortunately, this is only the problem of this test.

Resolve this by constructing the domain object from scratch.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Michal Privoznik 2020-05-21 20:55:01 +02:00
parent d265171b57
commit 69daa2ea8a
1 changed files with 12 additions and 2 deletions

View File

@ -482,16 +482,17 @@ testCompareXMLToArgvCreateArgs(virQEMUDriverPtr drv,
static int static int
testCompareXMLToArgvValidateSchema(virQEMUDriverPtr drv, testCompareXMLToArgvValidateSchema(virQEMUDriverPtr drv,
virDomainObjPtr vm,
const char *migrateURI, const char *migrateURI,
struct testQemuInfo *info, struct testQemuInfo *info,
unsigned int flags) unsigned int flags)
{ {
VIR_AUTOSTRINGLIST args = NULL; VIR_AUTOSTRINGLIST args = NULL;
g_autoptr(virDomainObj) vm = NULL;
size_t nargs = 0; size_t nargs = 0;
size_t i; size_t i;
g_autoptr(virHashTable) schema = NULL; g_autoptr(virHashTable) schema = NULL;
g_autoptr(virCommand) cmd = NULL; g_autoptr(virCommand) cmd = NULL;
unsigned int parseFlags = info->parseFlags;
if (info->schemafile) if (info->schemafile)
schema = testQEMUSchemaLoad(info->schemafile); schema = testQEMUSchemaLoad(info->schemafile);
@ -504,6 +505,15 @@ testCompareXMLToArgvValidateSchema(virQEMUDriverPtr drv,
if (!schema) if (!schema)
return 0; return 0;
if (!(vm = virDomainObjNew(driver.xmlopt)))
return -1;
parseFlags |= VIR_DOMAIN_DEF_PARSE_INACTIVE;
if (!(vm->def = virDomainDefParseFile(info->infile,
driver.xmlopt,
NULL, parseFlags)))
return -1;
if (!(cmd = testCompareXMLToArgvCreateArgs(drv, vm, migrateURI, info, flags, if (!(cmd = testCompareXMLToArgvCreateArgs(drv, vm, migrateURI, info, flags,
true))) true)))
return -1; return -1;
@ -651,7 +661,7 @@ testCompareXMLToArgv(const void *data)
goto cleanup; goto cleanup;
} }
if (testCompareXMLToArgvValidateSchema(&driver, vm, migrateURI, info, flags) < 0) if (testCompareXMLToArgvValidateSchema(&driver, migrateURI, info, flags) < 0)
goto cleanup; goto cleanup;
if (!(actualargv = virCommandToString(cmd, false))) if (!(actualargv = virCommandToString(cmd, false)))