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

View File

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