qemu_driver.c: use g_autoptr() with virDomainDef pointers

Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
Daniel Henrique Barboza 2020-11-12 13:44:35 -03:00
parent 6f0ee50be2
commit 74b2834333

View File

@ -1737,7 +1737,7 @@ static virDomainPtr qemuDomainCreateXML(virConnectPtr conn,
unsigned int flags)
{
virQEMUDriverPtr driver = conn->privateData;
virDomainDefPtr def = NULL;
g_autoptr(virDomainDef) def = NULL;
virDomainObjPtr vm = NULL;
virDomainPtr dom = NULL;
virObjectEventPtr event = NULL;
@ -1810,7 +1810,6 @@ static virDomainPtr qemuDomainCreateXML(virConnectPtr conn,
qemuProcessEndJob(driver, vm);
cleanup:
virDomainDefFree(def);
virDomainObjEndAPI(&vm);
virObjectEventStateQueue(driver->domainEventState, event);
virObjectEventStateQueue(driver->domainEventState, event2);
@ -5997,7 +5996,7 @@ qemuDomainRestoreFlags(virConnectPtr conn,
{
virQEMUDriverPtr driver = conn->privateData;
qemuDomainObjPrivatePtr priv = NULL;
virDomainDefPtr def = NULL;
g_autoptr(virDomainDef) def = NULL;
virDomainObjPtr vm = NULL;
g_autofree char *xmlout = NULL;
const char *newxml = dxml;
@ -6078,7 +6077,6 @@ qemuDomainRestoreFlags(virConnectPtr conn,
qemuProcessEndJob(driver, vm);
cleanup:
virDomainDefFree(def);
VIR_FORCE_CLOSE(fd);
if (virFileWrapperFdClose(wrapperFd) < 0)
ret = -1;
@ -6104,7 +6102,7 @@ qemuDomainSaveImageGetXMLDesc(virConnectPtr conn, const char *path,
{
virQEMUDriverPtr driver = conn->privateData;
char *ret = NULL;
virDomainDefPtr def = NULL;
g_autoptr(virDomainDef) def = NULL;
int fd = -1;
virQEMUSaveDataPtr data = NULL;
@ -6123,7 +6121,6 @@ qemuDomainSaveImageGetXMLDesc(virConnectPtr conn, const char *path,
cleanup:
virQEMUSaveDataFree(data);
virDomainDefFree(def);
VIR_FORCE_CLOSE(fd);
return ret;
}
@ -6134,8 +6131,8 @@ qemuDomainSaveImageDefineXML(virConnectPtr conn, const char *path,
{
virQEMUDriverPtr driver = conn->privateData;
int ret = -1;
virDomainDefPtr def = NULL;
virDomainDefPtr newdef = NULL;
g_autoptr(virDomainDef) def = NULL;
g_autoptr(virDomainDef) newdef = NULL;
int fd = -1;
virQEMUSaveDataPtr data = NULL;
int state = -1;
@ -6194,8 +6191,6 @@ qemuDomainSaveImageDefineXML(virConnectPtr conn, const char *path,
ret = 0;
cleanup:
virDomainDefFree(def);
virDomainDefFree(newdef);
VIR_FORCE_CLOSE(fd);
virQEMUSaveDataFree(data);
return ret;
@ -6208,7 +6203,7 @@ qemuDomainManagedSaveGetXMLDesc(virDomainPtr dom, unsigned int flags)
virDomainObjPtr vm;
g_autofree char *path = NULL;
char *ret = NULL;
virDomainDefPtr def = NULL;
g_autoptr(virDomainDef) def = NULL;
int fd = -1;
virQEMUSaveDataPtr data = NULL;
qemuDomainObjPrivatePtr priv;
@ -6240,7 +6235,6 @@ qemuDomainManagedSaveGetXMLDesc(virDomainPtr dom, unsigned int flags)
cleanup:
virQEMUSaveDataFree(data);
virDomainDefFree(def);
VIR_FORCE_CLOSE(fd);
virDomainObjEndAPI(&vm);
return ret;
@ -6289,7 +6283,7 @@ qemuDomainObjRestore(virConnectPtr conn,
bool bypass_cache,
qemuDomainAsyncJob asyncJob)
{
virDomainDefPtr def = NULL;
g_autoptr(virDomainDef) def = NULL;
qemuDomainObjPrivatePtr priv = vm->privateData;
int fd = -1;
int ret = -1;
@ -6350,7 +6344,6 @@ qemuDomainObjRestore(virConnectPtr conn,
cleanup:
virQEMUSaveDataFree(data);
virDomainDefFree(def);
VIR_FORCE_CLOSE(fd);
if (virFileWrapperFdClose(wrapperFd) < 0)
ret = -1;
@ -6689,8 +6682,8 @@ qemuDomainDefineXMLFlags(virConnectPtr conn,
unsigned int flags)
{
virQEMUDriverPtr driver = conn->privateData;
virDomainDefPtr def = NULL;
virDomainDefPtr oldDef = NULL;
g_autoptr(virDomainDef) def = NULL;
g_autoptr(virDomainDef) oldDef = NULL;
virDomainObjPtr vm = NULL;
virDomainPtr dom = NULL;
virObjectEventPtr event = NULL;
@ -6754,8 +6747,16 @@ qemuDomainDefineXMLFlags(virConnectPtr conn,
qemuDomainRemoveInactiveJob(driver, vm);
}
}
virDomainDefFree(oldDef);
virDomainDefFree(def);
event = virDomainEventLifecycleNewFromObj(vm,
VIR_DOMAIN_EVENT_DEFINED,
!oldDef ?
VIR_DOMAIN_EVENT_DEFINED_ADDED :
VIR_DOMAIN_EVENT_DEFINED_UPDATED);
VIR_INFO("Creating domain '%s'", vm->def->name);
dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
virDomainObjEndAPI(&vm);
virObjectEventStateQueue(driver->domainEventState, event);
return dom;
@ -7758,7 +7759,7 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObjPtr vm,
unsigned int flags)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
virDomainDefPtr vmdef = NULL;
g_autoptr(virDomainDef) vmdef = NULL;
g_autoptr(virQEMUDriverConfig) cfg = NULL;
virDomainDeviceDefPtr devConf = NULL;
virDomainDeviceDef devConfSave = { 0 };
@ -7848,7 +7849,6 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObjPtr vm,
ret = 0;
cleanup:
virDomainDefFree(vmdef);
virDomainDeviceDefFree(devConf);
virDomainDeviceDefFree(devLive);
@ -7906,7 +7906,7 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom,
virQEMUDriverPtr driver = dom->conn->privateData;
virDomainObjPtr vm = NULL;
qemuDomainObjPrivatePtr priv;
virDomainDefPtr vmdef = NULL;
g_autoptr(virDomainDef) vmdef = NULL;
virDomainDeviceDefPtr dev = NULL, dev_copy = NULL;
bool force = (flags & VIR_DOMAIN_DEVICE_MODIFY_FORCE) != 0;
int ret = -1;
@ -8001,7 +8001,6 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom,
qemuDomainObjEndJob(driver, vm);
cleanup:
virDomainDefFree(vmdef);
if (dev != dev_copy)
virDomainDeviceDefFree(dev_copy);
virDomainDeviceDefFree(dev);
@ -8020,7 +8019,7 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriverPtr driver,
g_autoptr(virQEMUDriverConfig) cfg = NULL;
virDomainDeviceDefPtr dev = NULL, dev_copy = NULL;
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE;
virDomainDefPtr vmdef = NULL;
g_autoptr(virDomainDef) vmdef = NULL;
int ret = -1;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
@ -8095,7 +8094,6 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriverPtr driver,
if (dev != dev_copy)
virDomainDeviceDefFree(dev_copy);
virDomainDeviceDefFree(dev);
virDomainDefFree(vmdef);
return ret;
}
@ -8110,7 +8108,7 @@ qemuDomainDetachDeviceAliasLiveAndConfig(virQEMUDriverPtr driver,
g_autoptr(virQEMUDriverConfig) cfg = NULL;
virDomainDefPtr def = NULL;
virDomainDefPtr persistentDef = NULL;
virDomainDefPtr vmdef = NULL;
g_autoptr(virDomainDef) vmdef = NULL;
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE;
int ret = -1;
@ -8164,7 +8162,6 @@ qemuDomainDetachDeviceAliasLiveAndConfig(virQEMUDriverPtr driver,
ret = 0;
cleanup:
virDomainDefFree(vmdef);
return ret;
}
@ -9284,7 +9281,7 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
virDomainObjPtr vm = NULL;
virDomainDefPtr def = NULL;
virDomainDefPtr persistentDef = NULL;
virDomainDefPtr persistentDefCopy = NULL;
g_autoptr(virDomainDef) persistentDefCopy = NULL;
unsigned long long value_ul;
long long value_l;
int ret = -1;
@ -9572,7 +9569,6 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
qemuDomainObjEndJob(driver, vm);
cleanup:
virDomainDefFree(persistentDefCopy);
virDomainObjEndAPI(&vm);
if (eventNparams)
virTypedParamsFree(eventParams, eventNparams);
@ -11171,7 +11167,7 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
const char *dom_xml)
{
virQEMUDriverPtr driver = dconn->privateData;
virDomainDefPtr def = NULL;
g_autoptr(virDomainDef) def = NULL;
g_autofree char *origname = NULL;
qemuMigrationParamsPtr migParams = NULL;
int ret = -1;
@ -11207,7 +11203,6 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
cleanup:
qemuMigrationParamsFree(migParams);
virDomainDefFree(def);
return ret;
}
@ -11227,7 +11222,7 @@ qemuDomainMigratePrepare2(virConnectPtr dconn,
const char *dom_xml)
{
virQEMUDriverPtr driver = dconn->privateData;
virDomainDefPtr def = NULL;
g_autoptr(virDomainDef) def = NULL;
g_autofree char *origname = NULL;
qemuMigrationParamsPtr migParams = NULL;
int ret = -1;
@ -11273,7 +11268,6 @@ qemuDomainMigratePrepare2(virConnectPtr dconn,
cleanup:
qemuMigrationParamsFree(migParams);
virDomainDefFree(def);
return ret;
}
@ -11615,7 +11609,7 @@ qemuDomainMigratePrepareTunnel3(virConnectPtr dconn,
const char *dom_xml)
{
virQEMUDriverPtr driver = dconn->privateData;
virDomainDefPtr def = NULL;
g_autoptr(virDomainDef) def = NULL;
g_autofree char *origname = NULL;
qemuMigrationParamsPtr migParams = NULL;
int ret = -1;
@ -11645,7 +11639,6 @@ qemuDomainMigratePrepareTunnel3(virConnectPtr dconn,
cleanup:
qemuMigrationParamsFree(migParams);
virDomainDefFree(def);
return ret;
}
@ -11661,7 +11654,7 @@ qemuDomainMigratePrepareTunnel3Params(virConnectPtr dconn,
unsigned int flags)
{
virQEMUDriverPtr driver = dconn->privateData;
virDomainDefPtr def = NULL;
g_autoptr(virDomainDef) def = NULL;
const char *dom_xml = NULL;
const char *dname = NULL;
g_autofree char *origname = NULL;
@ -11703,7 +11696,6 @@ qemuDomainMigratePrepareTunnel3Params(virConnectPtr dconn,
cleanup:
qemuMigrationParamsFree(migParams);
virDomainDefFree(def);
return ret;
}