Instead of calling virDomainDefFree() explicitly, we can annotate
variables with g_autoptr().
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/bhyve/bhyve_driver.c | 15 +++++--------
src/bhyve/bhyve_parse_command.c | 8 ++-----
src/ch/ch_driver.c | 6 ++----
src/conf/domain_conf.c | 6 ++----
src/conf/virdomainobjlist.c | 6 ++----
src/esx/esx_driver.c | 14 ++++--------
src/libxl/libxl_domain.c | 12 ++++-------
src/libxl/libxl_driver.c | 38 +++++++++++----------------------
src/libxl/libxl_migration.c | 3 +--
src/libxl/xen_xl.c | 5 ++---
src/libxl/xen_xm.c | 5 ++---
src/lxc/lxc_driver.c | 24 +++++++--------------
src/lxc/lxc_native.c | 5 ++---
src/openvz/openvz_conf.c | 3 +--
src/openvz/openvz_driver.c | 9 +++-----
src/qemu/qemu_saveimage.c | 7 ++----
src/qemu/qemu_snapshot.c | 6 ++----
src/test/test_driver.c | 27 ++++++++---------------
src/vbox/vbox_common.c | 14 ++++--------
src/vmware/vmware_conf.c | 6 ++----
src/vmware/vmware_driver.c | 10 +++------
src/vmx/vmx.c | 12 +++++------
src/vz/vz_driver.c | 6 ++----
src/vz/vz_sdk.c | 6 ++----
tests/securityselinuxtest.c | 8 +++----
25 files changed, 87 insertions(+), 174 deletions(-)
diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index eccf9b44a8..250e10b9d0 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -504,8 +504,8 @@ bhyveDomainDefineXMLFlags(virConnectPtr conn, const char *xml,
unsigned int flag
{
struct _bhyveConn *privconn = conn->privateData;
virDomainPtr dom = NULL;
- virDomainDef *def = NULL;
- virDomainDef *oldDef = NULL;
+ g_autoptr(virDomainDef) def = NULL;
+ g_autoptr(virDomainDef) oldDef = NULL;
virDomainObj *vm = NULL;
virObjectEvent *event = NULL;
virCaps *caps = NULL;
@@ -555,8 +555,6 @@ bhyveDomainDefineXMLFlags(virConnectPtr conn, const char *xml,
unsigned int flag
cleanup:
virObjectUnref(caps);
- virDomainDefFree(def);
- virDomainDefFree(oldDef);
virDomainObjEndAPI(&vm);
virObjectEventStateQueue(privconn->domainEventState, event);
@@ -679,7 +677,7 @@ bhyveConnectDomainXMLToNative(virConnectPtr conn,
{
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
struct _bhyveConn *privconn = conn->privateData;
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
virCommand *cmd = NULL;
virCommand *loadcmd = NULL;
char *ret = NULL;
@@ -736,7 +734,6 @@ bhyveConnectDomainXMLToNative(virConnectPtr conn,
cleanup:
virCommandFree(loadcmd);
virCommandFree(cmd);
- virDomainDefFree(def);
return ret;
}
@@ -890,7 +887,7 @@ bhyveDomainCreateXML(virConnectPtr conn,
{
struct _bhyveConn *privconn = conn->privateData;
virDomainPtr dom = NULL;
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
virDomainObj *vm = NULL;
virObjectEvent *event = NULL;
unsigned int start_flags = 0;
@@ -936,7 +933,6 @@ bhyveDomainCreateXML(virConnectPtr conn,
dom = virGetDomain(conn, vm->def->name, vm->def->uuid,
vm->def->id);
cleanup:
- virDomainDefFree(def);
virDomainObjEndAPI(&vm);
virObjectEventStateQueue(privconn->domainEventState, event);
@@ -1570,7 +1566,7 @@ bhyveConnectDomainXMLFromNative(virConnectPtr conn,
unsigned int flags)
{
char *xml = NULL;
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
struct _bhyveConn *privconn = conn->privateData;
unsigned bhyveCaps = bhyveDriverGetBhyveCaps(privconn);
@@ -1593,7 +1589,6 @@ bhyveConnectDomainXMLFromNative(virConnectPtr conn,
xml = virDomainDefFormat(def, privconn->xmlopt, 0);
cleanup:
- virDomainDefFree(def);
return xml;
}
diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
index f2c15f3aa5..6ee3c8305b 100644
--- a/src/bhyve/bhyve_parse_command.c
+++ b/src/bhyve/bhyve_parse_command.c
@@ -934,7 +934,7 @@ bhyveParseCommandLineString(const char* nativeConfig,
unsigned caps,
virDomainXMLOption *xmlopt)
{
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
int bhyve_argc = 0;
g_auto(GStrv) bhyve_argv = NULL;
int loader_argc = 0;
@@ -948,8 +948,6 @@ bhyveParseCommandLineString(const char* nativeConfig,
if (virUUIDGenerate(def->uuid) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Failed to generate uuid"));
- virDomainDefFree(def);
- def = NULL;
goto cleanup;
}
def->id = -1;
@@ -974,9 +972,7 @@ bhyveParseCommandLineString(const char* nativeConfig,
}
cleanup:
- return def;
+ return g_steal_pointer(&def);
error:
- virDomainDefFree(def);
- def = NULL;
goto cleanup;
}
diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c
index 464bcef907..108644e503 100644
--- a/src/ch/ch_driver.c
+++ b/src/ch/ch_driver.c
@@ -218,7 +218,7 @@ chDomainCreateXML(virConnectPtr conn,
unsigned int flags)
{
virCHDriver *driver = conn->privateData;
- virDomainDef *vmdef = NULL;
+ g_autoptr(virDomainDef) vmdef = NULL;
virDomainObj *vm = NULL;
virDomainPtr dom = NULL;
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
@@ -258,7 +258,6 @@ chDomainCreateXML(virConnectPtr conn,
if (vm && !dom) {
virDomainObjListRemove(driver->domains, vm);
}
- virDomainDefFree(vmdef);
virDomainObjEndAPI(&vm);
chDriverUnlock(driver);
return dom;
@@ -301,7 +300,7 @@ static virDomainPtr
chDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
{
virCHDriver *driver = conn->privateData;
- virDomainDef *vmdef = NULL;
+ g_autoptr(virDomainDef) vmdef = NULL;
virDomainObj *vm = NULL;
virDomainPtr dom = NULL;
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
@@ -331,7 +330,6 @@ chDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned
int flags)
dom = virGetDomain(conn, vm->def->name, vm->def->uuid,
vm->def->id);
cleanup:
- virDomainDefFree(vmdef);
virDomainObjEndAPI(&vm);
return dom;
}
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index bdcc3dc2c1..4059acba7f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -3840,7 +3840,7 @@ virDomainObjNew(virDomainXMLOption *xmlopt)
virDomainDef *
virDomainDefNew(virDomainXMLOption *xmlopt)
{
- virDomainDef *ret;
+ g_autoptr(virDomainDef) ret = NULL;
ret = g_new0(virDomainDef, 1);
@@ -3856,10 +3856,8 @@ virDomainDefNew(virDomainXMLOption *xmlopt)
else
ret->scsiBusMaxUnit = SCSI_NARROW_BUS_MAX_CONT_UNIT;
- return ret;
-
+ return g_steal_pointer(&ret);
error:
- virDomainDefFree(ret);
return NULL;
}
diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c
index a0cffac1b8..7d3828162b 100644
--- a/src/conf/virdomainobjlist.c
+++ b/src/conf/virdomainobjlist.c
@@ -483,10 +483,10 @@ virDomainObjListLoadConfig(virDomainObjList *doms,
{
g_autofree char *configFile = NULL;
g_autofree char *autostartLink = NULL;
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
virDomainObj *dom;
int autostart;
- virDomainDef *oldDef = NULL;
+ g_autoptr(virDomainDef) oldDef = NULL;
if ((configFile = virDomainConfigFile(configDir, name)) == NULL)
goto error;
@@ -510,11 +510,9 @@ virDomainObjListLoadConfig(virDomainObjList *doms,
if (notify)
(*notify)(dom, oldDef == NULL, opaque);
- virDomainDefFree(oldDef);
return dom;
error:
- virDomainDefFree(def);
return NULL;
}
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 99e433ce93..467740804a 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -2535,7 +2535,7 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
g_autofree char *vmx = NULL;
virVMXContext ctx;
esxVMX_Data data;
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
char *xml = NULL;
virCheckFlags(VIR_DOMAIN_XML_COMMON_FLAGS, NULL);
@@ -2607,7 +2607,6 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&virtualMachine);
g_free(data.datastorePathWithoutFileName);
- virDomainDefFree(def);
return xml;
}
@@ -2622,7 +2621,7 @@ esxConnectDomainXMLFromNative(virConnectPtr conn, const char
*nativeFormat,
esxPrivate *priv = conn->privateData;
virVMXContext ctx;
esxVMX_Data data;
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
char *xml = NULL;
virCheckFlags(0, NULL);
@@ -2651,8 +2650,6 @@ esxConnectDomainXMLFromNative(virConnectPtr conn, const char
*nativeFormat,
xml = virDomainDefFormat(def, priv->xmlopt,
VIR_DOMAIN_DEF_FORMAT_INACTIVE);
- virDomainDefFree(def);
-
return xml;
}
@@ -2667,7 +2664,7 @@ esxConnectDomainXMLToNative(virConnectPtr conn, const char
*nativeFormat,
int virtualHW_version;
virVMXContext ctx;
esxVMX_Data data;
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
char *vmx = NULL;
virCheckFlags(0, NULL);
@@ -2704,8 +2701,6 @@ esxConnectDomainXMLToNative(virConnectPtr conn, const char
*nativeFormat,
vmx = virVMXFormatConfig(&ctx, priv->xmlopt, def, virtualHW_version);
- virDomainDefFree(def);
-
return vmx;
}
@@ -2866,7 +2861,7 @@ static virDomainPtr
esxDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
{
esxPrivate *priv = conn->privateData;
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
g_autofree char *vmx = NULL;
size_t i;
virDomainDiskDef *disk = NULL;
@@ -3065,7 +3060,6 @@ esxDomainDefineXMLFlags(virConnectPtr conn, const char *xml,
unsigned int flags)
/* FIXME: Add proper rollback in case of an error */
cleanup:
- virDomainDefFree(def);
esxVI_ObjectContent_Free(&virtualMachine);
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&hostSystem);
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index db2966a599..b3a9521e16 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -743,7 +743,7 @@ libxlDomainSaveImageOpen(libxlDriverPrivate *driver,
libxlSavefileHeader *ret_hdr)
{
int fd;
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
libxlSavefileHeader hdr;
g_autofree char *xml = NULL;
@@ -795,7 +795,6 @@ libxlDomainSaveImageOpen(libxlDriverPrivate *driver,
return fd;
error:
- virDomainDefFree(def);
VIR_FORCE_CLOSE(fd);
return -1;
}
@@ -1425,7 +1424,7 @@ libxlDomainStartNew(libxlDriverPrivate *driver,
{
g_autofree char *managed_save_path = NULL;
int restore_fd = -1;
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
libxlSavefileHeader hdr;
uint32_t restore_ver = LIBXL_SAVE_VERSION;
int ret = -1;
@@ -1468,7 +1467,6 @@ libxlDomainStartNew(libxlDriverPrivate *driver,
ret = libxlDomainStart(driver, vm, start_paused, restore_fd, restore_ver);
cleanup:
- virDomainDefFree(def);
VIR_FORCE_CLOSE(restore_fd);
return ret;
}
@@ -1489,9 +1487,9 @@ libxlDomainDefCheckABIStability(libxlDriverPrivate *driver,
virDomainDef *src,
virDomainDef *dst)
{
- virDomainDef *migratableDefSrc = NULL;
- virDomainDef *migratableDefDst = NULL;
bool ret = false;
+ g_autoptr(virDomainDef) migratableDefSrc = NULL;
+ g_autoptr(virDomainDef) migratableDefDst = NULL;
if (!(migratableDefSrc = virDomainDefCopy(src, driver->xmlopt, NULL, true)) ||
!(migratableDefDst = virDomainDefCopy(dst, driver->xmlopt, NULL, true)))
@@ -1502,8 +1500,6 @@ libxlDomainDefCheckABIStability(libxlDriverPrivate *driver,
driver->xmlopt);
cleanup:
- virDomainDefFree(migratableDefSrc);
- virDomainDefFree(migratableDefDst);
return ret;
}
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 23a28dc124..5b49089f7d 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -563,7 +563,7 @@ static int
libxlAddDom0(libxlDriverPrivate *driver)
{
libxlDriverConfig *cfg = libxlDriverConfigGet(driver);
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
virDomainObj *vm = NULL;
libxl_dominfo d_info;
unsigned long long maxmem;
@@ -619,7 +619,6 @@ libxlAddDom0(libxlDriverPrivate *driver)
cleanup:
libxl_dominfo_dispose(&d_info);
- virDomainDefFree(def);
virDomainObjEndAPI(&vm);
virObjectUnref(cfg);
return ret;
@@ -1008,7 +1007,7 @@ libxlDomainCreateXML(virConnectPtr conn, const char *xml,
unsigned int flags)
{
libxlDriverPrivate *driver = conn->privateData;
- virDomainDef *def;
+ g_autoptr(virDomainDef) def = NULL;
virDomainObj *vm = NULL;
virDomainPtr dom = NULL;
libxlDriverConfig *cfg = libxlDriverConfigGet(driver);
@@ -1053,7 +1052,6 @@ libxlDomainCreateXML(virConnectPtr conn, const char *xml,
libxlDomainObjEndJob(driver, vm);
cleanup:
- virDomainDefFree(def);
virDomainObjEndAPI(&vm);
virObjectUnref(cfg);
return dom;
@@ -1922,7 +1920,7 @@ libxlDomainRestoreFlags(virConnectPtr conn, const char *from,
{
libxlDriverPrivate *driver = conn->privateData;
virDomainObj *vm = NULL;
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
libxlSavefileHeader hdr;
int fd = -1;
int ret = -1;
@@ -1970,7 +1968,6 @@ libxlDomainRestoreFlags(virConnectPtr conn, const char *from,
cleanup:
if (VIR_CLOSE(fd) < 0)
virReportSystemError(errno, "%s", _("cannot close file"));
- virDomainDefFree(def);
virDomainObjEndAPI(&vm);
return ret;
}
@@ -2633,7 +2630,7 @@ libxlConnectDomainXMLFromNative(virConnectPtr conn,
{
libxlDriverPrivate *driver = conn->privateData;
libxlDriverConfig *cfg = libxlDriverConfigGet(driver);
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
g_autoptr(virConf) conf = NULL;
char *xml = NULL;
@@ -2670,7 +2667,6 @@ libxlConnectDomainXMLFromNative(virConnectPtr conn,
xml = virDomainDefFormat(def, driver->xmlopt, VIR_DOMAIN_DEF_FORMAT_INACTIVE);
cleanup:
- virDomainDefFree(def);
virObjectUnref(cfg);
return xml;
}
@@ -2683,7 +2679,7 @@ libxlConnectDomainXMLToNative(virConnectPtr conn, const char *
nativeFormat,
{
libxlDriverPrivate *driver = conn->privateData;
libxlDriverConfig *cfg = libxlDriverConfigGet(driver);
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
g_autoptr(virConf) conf = NULL;
int len = MAX_CONFIG_SIZE;
char *ret = NULL;
@@ -2719,7 +2715,6 @@ libxlConnectDomainXMLToNative(virConnectPtr conn, const char *
nativeFormat,
}
cleanup:
- virDomainDefFree(def);
virObjectUnref(cfg);
return ret;
}
@@ -2801,11 +2796,11 @@ libxlDomainDefineXMLFlags(virConnectPtr conn, const char *xml,
unsigned int flag
{
libxlDriverPrivate *driver = conn->privateData;
libxlDriverConfig *cfg = libxlDriverConfigGet(driver);
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
virDomainObj *vm = NULL;
virDomainPtr dom = NULL;
virObjectEvent *event = NULL;
- virDomainDef *oldDef = NULL;
+ g_autoptr(virDomainDef) oldDef = NULL;
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
virCheckFlags(VIR_DOMAIN_DEFINE_VALIDATE, NULL);
@@ -2845,8 +2840,6 @@ libxlDomainDefineXMLFlags(virConnectPtr conn, const char *xml,
unsigned int flag
VIR_DOMAIN_EVENT_DEFINED_UPDATED);
cleanup:
- virDomainDefFree(def);
- virDomainDefFree(oldDef);
virDomainObjEndAPI(&vm);
virObjectEventStateQueue(driver->domainEventState, event);
virObjectUnref(cfg);
@@ -4072,7 +4065,7 @@ libxlDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
libxlDriverPrivate *driver = dom->conn->privateData;
libxlDriverConfig *cfg = libxlDriverConfigGet(driver);
virDomainObj *vm = NULL;
- virDomainDef *vmdef = NULL;
+ g_autoptr(virDomainDef) vmdef = NULL;
virDomainDeviceDef *devConf = NULL;
virDomainDeviceDef devConfSave = { 0 };
virDomainDeviceDef *devLive = NULL;
@@ -4147,7 +4140,6 @@ libxlDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
libxlDomainObjEndJob(driver, vm);
cleanup:
- virDomainDefFree(vmdef);
virDomainDeviceDefFree(devConf);
virDomainDeviceDefFree(devLive);
virDomainObjEndAPI(&vm);
@@ -4169,7 +4161,7 @@ libxlDomainDetachDeviceFlags(virDomainPtr dom, const char *xml,
libxlDriverPrivate *driver = dom->conn->privateData;
libxlDriverConfig *cfg = libxlDriverConfigGet(driver);
virDomainObj *vm = NULL;
- virDomainDef *vmdef = NULL;
+ g_autoptr(virDomainDef) vmdef = NULL;
virDomainDeviceDef *dev = NULL;
int ret = -1;
@@ -4236,7 +4228,6 @@ libxlDomainDetachDeviceFlags(virDomainPtr dom, const char *xml,
libxlDomainObjEndJob(driver, vm);
cleanup:
- virDomainDefFree(vmdef);
virDomainDeviceDefFree(dev);
virDomainObjEndAPI(&vm);
virObjectUnref(cfg);
@@ -4257,7 +4248,7 @@ libxlDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml,
libxlDriverPrivate *driver = dom->conn->privateData;
libxlDriverConfig *cfg = libxlDriverConfigGet(driver);
virDomainObj *vm = NULL;
- virDomainDef *vmdef = NULL;
+ g_autoptr(virDomainDef) vmdef = NULL;
virDomainDeviceDef *dev = NULL;
int ret = -1;
@@ -4316,7 +4307,6 @@ libxlDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml,
}
cleanup:
- virDomainDefFree(vmdef);
virDomainDeviceDefFree(dev);
virDomainObjEndAPI(&vm);
virObjectUnref(cfg);
@@ -5822,7 +5812,7 @@ libxlDomainMigratePrepareTunnel3Params(virConnectPtr dconn,
unsigned int flags)
{
libxlDriverPrivate *driver = dconn->privateData;
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
const char *dom_xml = NULL;
const char *dname = NULL;
const char *uri_in = NULL;
@@ -5861,7 +5851,6 @@ libxlDomainMigratePrepareTunnel3Params(virConnectPtr dconn,
return 0;
error:
- virDomainDefFree(def);
return -1;
}
@@ -5877,7 +5866,7 @@ libxlDomainMigratePrepare3Params(virConnectPtr dconn,
unsigned int flags)
{
libxlDriverPrivate *driver = dconn->privateData;
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
const char *dom_xml = NULL;
const char *dname = NULL;
const char *uri_in = NULL;
@@ -5889,7 +5878,7 @@ libxlDomainMigratePrepare3Params(virConnectPtr dconn,
virCheckFlags(LIBXL_MIGRATION_FLAGS, -1);
if (virTypedParamsValidate(params, nparams, LIBXL_MIGRATION_PARAMETERS) < 0)
- goto error;
+ return -1;
if (virTypedParamsGetString(params, nparams,
VIR_MIGRATE_PARAM_DEST_XML,
@@ -5916,7 +5905,6 @@ libxlDomainMigratePrepare3Params(virConnectPtr dconn,
return 0;
error:
- virDomainDefFree(def);
return -1;
}
diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c
index cdd714d6b8..6d0ab4ee28 100644
--- a/src/libxl/libxl_migration.c
+++ b/src/libxl/libxl_migration.c
@@ -379,7 +379,7 @@ libxlDomainMigrationSrcBegin(virConnectPtr conn,
libxlDriverPrivate *driver = conn->privateData;
libxlDriverConfig *cfg = libxlDriverConfigGet(driver);
libxlMigrationCookie *mig = NULL;
- virDomainDef *tmpdef = NULL;
+ g_autoptr(virDomainDef) tmpdef = NULL;
virDomainDef *def;
char *xml = NULL;
@@ -426,7 +426,6 @@ libxlDomainMigrationSrcBegin(virConnectPtr conn,
cleanup:
libxlMigrationCookieFree(mig);
- virDomainDefFree(tmpdef);
virObjectUnref(cfg);
return xml;
}
diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c
index 17c5184b9b..fc05f8f502 100644
--- a/src/libxl/xen_xl.c
+++ b/src/libxl/xen_xl.c
@@ -1115,7 +1115,7 @@ xenParseXL(virConf *conf,
virCaps *caps,
virDomainXMLOption *xmlopt)
{
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
if (!(def = virDomainDefNew(xmlopt)))
return NULL;
@@ -1165,10 +1165,9 @@ xenParseXL(virConf *conf,
xmlopt, NULL) < 0)
goto cleanup;
- return def;
+ return g_steal_pointer(&def);
cleanup:
- virDomainDefFree(def);
return NULL;
}
diff --git a/src/libxl/xen_xm.c b/src/libxl/xen_xm.c
index ffcd4a7e8f..1fc3e99b08 100644
--- a/src/libxl/xen_xm.c
+++ b/src/libxl/xen_xm.c
@@ -408,7 +408,7 @@ xenParseXM(virConf *conf,
virCaps *caps,
virDomainXMLOption *xmlopt)
{
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
if (!(def = virDomainDefNew(xmlopt)))
return NULL;
@@ -433,10 +433,9 @@ xenParseXM(virConf *conf,
xmlopt, NULL) < 0)
goto cleanup;
- return def;
+ return g_steal_pointer(&def);
cleanup:
- virDomainDefFree(def);
return NULL;
}
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 3cdf73c69f..349783ca7c 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -399,11 +399,11 @@ static virDomainPtr
lxcDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
{
virLXCDriver *driver = conn->privateData;
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
virDomainObj *vm = NULL;
virDomainPtr dom = NULL;
virObjectEvent *event = NULL;
- virDomainDef *oldDef = NULL;
+ g_autoptr(virDomainDef) oldDef = NULL;
virLXCDriverConfig *cfg = virLXCDriverGetConfig(driver);
virCaps *caps = NULL;
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
@@ -457,8 +457,6 @@ lxcDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned
int flags)
dom = virGetDomain(conn, vm->def->name, vm->def->uuid,
vm->def->id);
cleanup:
- virDomainDefFree(def);
- virDomainDefFree(oldDef);
virDomainObjEndAPI(&vm);
virObjectEventStateQueue(driver->domainEventState, event);
virObjectUnref(caps);
@@ -937,7 +935,7 @@ static char *lxcConnectDomainXMLFromNative(virConnectPtr conn,
unsigned int flags)
{
char *xml = NULL;
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
virLXCDriver *driver = conn->privateData;
virCaps *caps = virLXCDriverGetCapabilities(driver, false);
@@ -959,7 +957,6 @@ static char *lxcConnectDomainXMLFromNative(virConnectPtr conn,
cleanup:
virObjectUnref(caps);
- virDomainDefFree(def);
return xml;
}
@@ -1081,7 +1078,7 @@ lxcDomainCreateXMLWithFiles(virConnectPtr conn,
{
virLXCDriver *driver = conn->privateData;
virDomainObj *vm = NULL;
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
virDomainPtr dom = NULL;
virObjectEvent *event = NULL;
virLXCDriverConfig *cfg = virLXCDriverGetConfig(driver);
@@ -1151,7 +1148,6 @@ lxcDomainCreateXMLWithFiles(virConnectPtr conn,
virLXCDomainObjEndJob(driver, vm);
cleanup:
- virDomainDefFree(def);
virDomainObjEndAPI(&vm);
virObjectEventStateQueue(driver->domainEventState, event);
virObjectUnref(caps);
@@ -1811,7 +1807,7 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr dom,
size_t i;
virDomainObj *vm = NULL;
virDomainDef *def = NULL;
- virDomainDef *persistentDefCopy = NULL;
+ g_autoptr(virDomainDef) persistentDefCopy = NULL;
virDomainDef *persistentDef = NULL;
int ret = -1;
int rc;
@@ -1924,7 +1920,6 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr dom,
virLXCDomainObjEndJob(driver, vm);
cleanup:
- virDomainDefFree(persistentDefCopy);
virDomainObjEndAPI(&vm);
virObjectUnref(caps);
virObjectUnref(cfg);
@@ -4289,7 +4284,7 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom,
{
virLXCDriver *driver = dom->conn->privateData;
virDomainObj *vm = NULL;
- virDomainDef *vmdef = NULL;
+ g_autoptr(virDomainDef) vmdef = NULL;
virDomainDeviceDef *dev = NULL;
virDomainDeviceDef *dev_copy = NULL;
int ret = -1;
@@ -4373,7 +4368,6 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom,
virLXCDomainObjEndJob(driver, vm);
cleanup:
- virDomainDefFree(vmdef);
if (dev != dev_copy)
virDomainDeviceDefFree(dev_copy);
virDomainDeviceDefFree(dev);
@@ -4397,7 +4391,7 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom,
{
virLXCDriver *driver = dom->conn->privateData;
virDomainObj *vm = NULL;
- virDomainDef *vmdef = NULL;
+ g_autoptr(virDomainDef) vmdef = NULL;
virDomainDeviceDef *dev = NULL;
int ret = -1;
virLXCDriverConfig *cfg = virLXCDriverGetConfig(driver);
@@ -4446,7 +4440,6 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom,
virLXCDomainObjEndJob(driver, vm);
cleanup:
- virDomainDefFree(vmdef);
virDomainDeviceDefFree(dev);
virDomainObjEndAPI(&vm);
virObjectUnref(cfg);
@@ -4461,7 +4454,7 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom,
virLXCDriver *driver = dom->conn->privateData;
virCaps *caps = NULL;
virDomainObj *vm = NULL;
- virDomainDef *vmdef = NULL;
+ g_autoptr(virDomainDef) vmdef = NULL;
virDomainDeviceDef *dev = NULL;
virDomainDeviceDef *dev_copy = NULL;
int ret = -1;
@@ -4539,7 +4532,6 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom,
virLXCDomainObjEndJob(driver, vm);
cleanup:
- virDomainDefFree(vmdef);
if (dev != dev_copy)
virDomainDeviceDefFree(dev_copy);
virDomainDeviceDefFree(dev);
diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index f3b8e85143..8f38c6e086 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -1086,7 +1086,7 @@ lxcParseConfigString(const char *config,
virCaps *caps G_GNUC_UNUSED,
virDomainXMLOption *xmlopt)
{
- virDomainDef *vmdef = NULL;
+ g_autoptr(virDomainDef) vmdef = NULL;
g_autoptr(virConf) properties = NULL;
g_autofree char *value = NULL;
@@ -1199,9 +1199,8 @@ lxcParseConfigString(const char *config,
xmlopt, NULL) < 0)
goto error;
- return vmdef;
+ return g_steal_pointer(&vmdef);
error:
- virDomainDefFree(vmdef);
return NULL;
}
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index e2fbc28abc..4fb18c03ee 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -446,7 +446,7 @@ int openvzLoadDomains(struct openvz_driver *driver)
char *status;
char uuidstr[VIR_UUID_STRING_BUFLEN];
virDomainObj *dom = NULL;
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
char *temp = NULL;
char *outbuf = NULL;
char *line;
@@ -559,7 +559,6 @@ int openvzLoadDomains(struct openvz_driver *driver)
virCommandFree(cmd);
VIR_FREE(temp);
VIR_FREE(outbuf);
- virDomainDefFree(def);
return -1;
}
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index d9c71a5722..ce3262c0e2 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -824,7 +824,7 @@ static virDomainPtr
openvzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
{
struct openvz_driver *driver = conn->privateData;
- virDomainDef *vmdef = NULL;
+ g_autoptr(virDomainDef) vmdef = NULL;
virDomainObj *vm = NULL;
virDomainPtr dom = NULL;
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
@@ -895,7 +895,6 @@ openvzDomainDefineXMLFlags(virConnectPtr conn, const char *xml,
unsigned int fla
dom = virGetDomain(conn, vm->def->name, vm->def->uuid, -1);
cleanup:
- virDomainDefFree(vmdef);
virDomainObjEndAPI(&vm);
openvzDriverUnlock(driver);
return dom;
@@ -913,7 +912,7 @@ openvzDomainCreateXML(virConnectPtr conn, const char *xml,
{
g_autoptr(virCommand) cmd = virCommandNewArgList(VZCTL, "--quiet",
"start", NULL);
struct openvz_driver *driver = conn->privateData;
- virDomainDef *vmdef = NULL;
+ g_autoptr(virDomainDef) vmdef = NULL;
virDomainObj *vm = NULL;
virDomainPtr dom = NULL;
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
@@ -983,7 +982,6 @@ openvzDomainCreateXML(virConnectPtr conn, const char *xml,
dom = virGetDomain(conn, vm->def->name, vm->def->uuid,
vm->def->id);
cleanup:
- virDomainDefFree(vmdef);
virDomainObjEndAPI(&vm);
openvzDriverUnlock(driver);
return dom;
@@ -2063,7 +2061,7 @@ openvzDomainMigratePrepare3Params(virConnectPtr dconn,
struct openvz_driver *driver = dconn->privateData;
const char *dom_xml = NULL;
const char *uri_in = NULL;
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
virDomainObj *vm = NULL;
g_autofree char *my_hostname = NULL;
const char *hostname = NULL;
@@ -2138,7 +2136,6 @@ openvzDomainMigratePrepare3Params(virConnectPtr dconn,
goto done;
error:
- virDomainDefFree(def);
if (vm)
virDomainObjListRemove(driver->domains, vm);
diff --git a/src/qemu/qemu_saveimage.c b/src/qemu/qemu_saveimage.c
index e14e2987f1..cdba3aa34d 100644
--- a/src/qemu/qemu_saveimage.c
+++ b/src/qemu/qemu_saveimage.c
@@ -719,8 +719,8 @@ qemuSaveImageUpdateDef(virQEMUDriver *driver,
const char *newxml)
{
virDomainDef *ret = NULL;
- virDomainDef *newdef_migr = NULL;
- virDomainDef *newdef = NULL;
+ g_autoptr(virDomainDef) newdef_migr = NULL;
+ g_autoptr(virDomainDef) newdef = NULL;
if (!(newdef = virDomainDefParseString(newxml, driver->xmlopt, NULL,
VIR_DOMAIN_DEF_PARSE_INACTIVE)))
@@ -756,8 +756,5 @@ qemuSaveImageUpdateDef(virQEMUDriver *driver,
}
cleanup:
- virDomainDefFree(newdef);
- virDomainDefFree(newdef_migr);
-
return ret;
}
diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c
index edf5511e42..5562646a9e 100644
--- a/src/qemu/qemu_snapshot.c
+++ b/src/qemu/qemu_snapshot.c
@@ -1940,8 +1940,8 @@ qemuSnapshotRevert(virDomainObj *vm,
int detail;
qemuDomainObjPrivate *priv = vm->privateData;
int rc;
- virDomainDef *config = NULL;
- virDomainDef *inactiveConfig = NULL;
+ g_autoptr(virDomainDef) config = NULL;
+ g_autoptr(virDomainDef) inactiveConfig = NULL;
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
qemuDomainSaveCookie *cookie;
virCPUDef *origCPU = NULL;
@@ -2235,8 +2235,6 @@ qemuSnapshotRevert(virDomainObj *vm,
virObjectEventStateQueue(driver->domainEventState, event);
virObjectEventStateQueue(driver->domainEventState, event2);
virCPUDefFree(origCPU);
- virDomainDefFree(config);
- virDomainDefFree(inactiveConfig);
return ret;
}
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index b6bca884f0..4d6ee3098e 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -1029,7 +1029,7 @@ testParseDomains(testDriver *privconn,
return -1;
for (i = 0; i < num; i++) {
- virDomainDef *def;
+ g_autoptr(virDomainDef) def = NULL;
testDomainNamespaceDef *nsdata;
xmlNodePtr node = testParseXMLDocFromFile(nodes[i], file, "domain");
if (!node)
@@ -1046,7 +1046,6 @@ testParseDomains(testDriver *privconn,
&def,
privconn->xmlopt,
0, NULL))) {
- virDomainDefFree(def);
goto error;
}
@@ -1750,7 +1749,7 @@ testDomainCreateXML(virConnectPtr conn, const char *xml,
{
testDriver *privconn = conn->privateData;
virDomainPtr ret = NULL;
- virDomainDef *def;
+ g_autoptr(virDomainDef) def = NULL;
virDomainObj *dom = NULL;
virObjectEvent *event = NULL;
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
@@ -1790,7 +1789,6 @@ testDomainCreateXML(virConnectPtr conn, const char *xml,
cleanup:
virDomainObjEndAPI(&dom);
virObjectEventStateQueue(privconn->eventState, event);
- virDomainDefFree(def);
virObjectUnlock(privconn);
return ret;
}
@@ -2388,7 +2386,7 @@ testDomainSaveImageOpen(testDriver *driver,
char magic[15];
int fd = -1;
int len;
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
g_autofree char *xml = NULL;
if ((fd = open(path, O_RDONLY)) < 0) {
@@ -2436,7 +2434,6 @@ testDomainSaveImageOpen(testDriver *driver,
return fd;
error:
- virDomainDefFree(def);
VIR_FORCE_CLOSE(fd);
return -1;
}
@@ -2498,7 +2495,7 @@ testDomainRestoreFlags(virConnectPtr conn,
{
testDriver *privconn = conn->privateData;
int fd = -1;
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
virDomainObj *dom = NULL;
virObjectEvent *event = NULL;
int ret = -1;
@@ -2535,7 +2532,6 @@ testDomainRestoreFlags(virConnectPtr conn,
ret = 0;
cleanup:
- virDomainDefFree(def);
VIR_FORCE_CLOSE(fd);
virDomainObjEndAPI(&dom);
virObjectEventStateQueue(privconn->eventState, event);
@@ -2558,8 +2554,8 @@ testDomainSaveImageDefineXML(virConnectPtr conn,
{
int ret = -1;
int fd = -1;
- virDomainDef *def = NULL;
- virDomainDef *newdef = NULL;
+ g_autoptr(virDomainDef) def = NULL;
+ g_autoptr(virDomainDef) newdef = NULL;
testDriver *privconn = conn->privateData;
virCheckFlags(VIR_DOMAIN_SAVE_RUNNING |
@@ -2579,8 +2575,6 @@ testDomainSaveImageDefineXML(virConnectPtr conn,
ret = 0;
cleanup:
- virDomainDefFree(def);
- virDomainDefFree(newdef);
return ret;
}
@@ -2592,7 +2586,7 @@ testDomainSaveImageGetXMLDesc(virConnectPtr conn,
{
int fd = -1;
char *ret = NULL;
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
testDriver *privconn = conn->privateData;
virCheckFlags(VIR_DOMAIN_SAVE_IMAGE_XML_SECURE, NULL);
@@ -2604,7 +2598,6 @@ testDomainSaveImageGetXMLDesc(virConnectPtr conn,
VIR_DOMAIN_DEF_FORMAT_SECURE);
cleanup:
- virDomainDefFree(def);
VIR_FORCE_CLOSE(fd);
return ret;
}
@@ -4185,10 +4178,10 @@ static virDomainPtr testDomainDefineXMLFlags(virConnectPtr conn,
{
testDriver *privconn = conn->privateData;
virDomainPtr ret = NULL;
- virDomainDef *def;
+ g_autoptr(virDomainDef) def = NULL;
virDomainObj *dom = NULL;
virObjectEvent *event = NULL;
- virDomainDef *oldDef = NULL;
+ g_autoptr(virDomainDef) oldDef = NULL;
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
virCheckFlags(VIR_DOMAIN_DEFINE_VALIDATE, NULL);
@@ -4222,8 +4215,6 @@ static virDomainPtr testDomainDefineXMLFlags(virConnectPtr conn,
ret = virGetDomain(conn, dom->def->name, dom->def->uuid,
dom->def->id);
cleanup:
- virDomainDefFree(def);
- virDomainDefFree(oldDef);
virDomainObjEndAPI(&dom);
virObjectEventStateQueue(privconn->eventState, event);
return ret;
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 72f1b9c466..d3251863e6 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -1858,7 +1858,7 @@ vboxDomainDefineXMLFlags(virConnectPtr conn, const char *xml,
unsigned int flags
IMachine *machine = NULL;
IBIOSSettings *bios = NULL;
vboxIID mchiid;
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
nsresult rc;
char uuidstr[VIR_UUID_STRING_BUFLEN];
virDomainPtr ret = NULL;
@@ -1979,8 +1979,6 @@ vboxDomainDefineXMLFlags(virConnectPtr conn, const char *xml,
unsigned int flags
/* if machine wasn't even created, cleanup is trivial */
if (!machine) {
vboxIIDUnalloc(&mchiid);
- virDomainDefFree(def);
-
return ret;
}
@@ -2013,7 +2011,6 @@ vboxDomainDefineXMLFlags(virConnectPtr conn, const char *xml,
unsigned int flags
VBOX_RELEASE(machine);
vboxIIDUnalloc(&mchiid);
- virDomainDefFree(def);
return ret;
}
@@ -3964,7 +3961,7 @@ vboxDumpParallel(virDomainDef *def, struct _vboxDriver *data,
IMachine *machine,
static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
{
struct _vboxDriver *data = dom->conn->privateData;
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
IMachine *machine = NULL;
vboxIID iid;
PRBool accessible = PR_FALSE;
@@ -4115,7 +4112,6 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int
flags)
cleanup:
VBOX_RELEASE(machine);
vboxIIDUnalloc(&iid);
- virDomainDefFree(def);
return ret;
}
@@ -4226,7 +4222,7 @@ static int vboxDomainAttachDeviceImpl(virDomainPtr dom,
IMachine *machine = NULL;
vboxIID iid;
PRUint32 state;
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
virDomainDeviceDef *dev = NULL;
nsresult rc;
int ret = -1;
@@ -4305,7 +4301,6 @@ static int vboxDomainAttachDeviceImpl(virDomainPtr dom,
cleanup:
vboxIIDUnalloc(&iid);
- virDomainDefFree(def);
virDomainDeviceDefFree(dev);
return ret;
}
@@ -4345,7 +4340,7 @@ static int vboxDomainDetachDevice(virDomainPtr dom, const char
*xml)
IMachine *machine = NULL;
vboxIID iid;
PRUint32 state;
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
virDomainDeviceDef *dev = NULL;
nsresult rc;
int ret = -1;
@@ -4422,7 +4417,6 @@ static int vboxDomainDetachDevice(virDomainPtr dom, const char
*xml)
cleanup:
vboxIIDUnalloc(&iid);
- virDomainDefFree(def);
virDomainDeviceDefFree(dev);
return ret;
}
diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c
index ab03617d95..8c8ecc8120 100644
--- a/src/vmware/vmware_conf.c
+++ b/src/vmware/vmware_conf.c
@@ -117,7 +117,6 @@ vmwareCapsInit(void)
int
vmwareLoadDomains(struct vmware_driver *driver)
{
- virDomainDef *vmdef = NULL;
virDomainObj *vm = NULL;
char *vmxPath = NULL;
char *vmx = NULL;
@@ -141,8 +140,8 @@ vmwareLoadDomains(struct vmware_driver *driver)
if (virCommandRun(cmd, NULL) < 0)
goto cleanup;
- for (str = outbuf; (vmxPath = strtok_r(str, "\n", &saveptr)) != NULL;
- str = NULL) {
+ for (str = outbuf; (vmxPath = strtok_r(str, "\n", &saveptr)) != NULL;
str = NULL) {
+ g_autoptr(virDomainDef) vmdef = NULL;
if (!g_path_is_absolute(vmxPath))
continue;
@@ -182,7 +181,6 @@ vmwareLoadDomains(struct vmware_driver *driver)
cleanup:
virCommandFree(cmd);
VIR_FREE(outbuf);
- virDomainDefFree(vmdef);
VIR_FREE(vmx);
virObjectUnref(vm);
return ret;
diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c
index e6843ee745..8f107dd529 100644
--- a/src/vmware/vmware_driver.c
+++ b/src/vmware/vmware_driver.c
@@ -394,7 +394,7 @@ static virDomainPtr
vmwareDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
{
struct vmware_driver *driver = conn->privateData;
- virDomainDef *vmdef = NULL;
+ g_autoptr(virDomainDef) vmdef = NULL;
virDomainObj *vm = NULL;
virDomainPtr dom = NULL;
char *vmx = NULL;
@@ -454,7 +454,6 @@ vmwareDomainDefineXMLFlags(virConnectPtr conn, const char *xml,
unsigned int fla
dom = virGetDomain(conn, vm->def->name, vm->def->uuid, -1);
cleanup:
- virDomainDefFree(vmdef);
VIR_FREE(vmx);
VIR_FREE(vmxPath);
if (vm)
@@ -646,7 +645,7 @@ vmwareDomainCreateXML(virConnectPtr conn, const char *xml,
unsigned int flags)
{
struct vmware_driver *driver = conn->privateData;
- virDomainDef *vmdef = NULL;
+ g_autoptr(virDomainDef) vmdef = NULL;
virDomainObj *vm = NULL;
virDomainPtr dom = NULL;
char *vmx = NULL;
@@ -709,7 +708,6 @@ vmwareDomainCreateXML(virConnectPtr conn, const char *xml,
dom = virGetDomain(conn, vm->def->name, vm->def->uuid,
vm->def->id);
cleanup:
- virDomainDefFree(vmdef);
VIR_FREE(vmx);
VIR_FREE(vmxPath);
virDomainObjEndAPI(&vm);
@@ -937,7 +935,7 @@ vmwareConnectDomainXMLFromNative(virConnectPtr conn, const char
*nativeFormat,
{
struct vmware_driver *driver = conn->privateData;
virVMXContext ctx;
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
char *xml = NULL;
virCheckFlags(0, NULL);
@@ -959,8 +957,6 @@ vmwareConnectDomainXMLFromNative(virConnectPtr conn, const char
*nativeFormat,
xml = virDomainDefFormat(def, driver->xmlopt,
VIR_DOMAIN_DEF_FORMAT_INACTIVE);
- virDomainDefFree(def);
-
return xml;
}
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index d3540acd84..ca65caa9a1 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -1382,7 +1382,7 @@ virVMXParseConfig(virVMXContext *ctx,
g_autoptr(virConf) conf = NULL;
char *encoding = NULL;
char *utf8;
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
long long config_version = 0;
long long virtualHW_version = 0;
long long memsize = 0;
@@ -1982,11 +1982,6 @@ virVMXParseConfig(virVMXContext *ctx,
success = true;
cleanup:
- if (! success) {
- virDomainDefFree(def);
- def = NULL;
- }
-
VIR_FREE(encoding);
VIR_FREE(sched_cpu_affinity);
VIR_FREE(sched_cpu_shares);
@@ -1994,7 +1989,10 @@ virVMXParseConfig(virVMXContext *ctx,
virCPUDefFree(cpu);
VIR_FREE(firmware);
- return def;
+ if (!success)
+ return NULL;
+
+ return g_steal_pointer(&def);
}
diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index 23b7795035..ff5f7cb2e7 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -788,7 +788,7 @@ vzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned
int flags)
{
struct _vzConn *privconn = conn->privateData;
virDomainPtr retdom = NULL;
- virDomainDef *def;
+ g_autoptr(virDomainDef) def = NULL;
virDomainObj *dom = NULL;
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
struct _vzDriver *driver = privconn->driver;
@@ -872,7 +872,6 @@ vzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned
int flags)
if (job)
vzDomainObjEndJob(dom);
virDomainObjEndAPI(&dom);
- virDomainDefFree(def);
return retdom;
}
@@ -2964,7 +2963,7 @@ vzDomainMigratePrepare3Params(virConnectPtr conn,
const char *miguri = NULL;
const char *dname = NULL;
const char *dom_xml = NULL;
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
int ret = -1;
virCheckFlags(VZ_MIGRATION_FLAGS, -1);
@@ -3009,7 +3008,6 @@ vzDomainMigratePrepare3Params(virConnectPtr conn,
ret = 0;
cleanup:
- virDomainDefFree(def);
return ret;
}
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index 1772f75c3e..7869b5c94d 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -1777,7 +1777,7 @@ prlsdkLoadDomain(struct _vzDriver *driver,
PRL_HANDLE sdkdom,
virDomainObj *dom)
{
- virDomainDef *def = NULL;
+ g_autoptr(virDomainDef) def = NULL;
struct vzDomObj *pdom = NULL;
VIRTUAL_MACHINE_STATE domainState;
@@ -1883,7 +1883,6 @@ prlsdkLoadDomain(struct _vzDriver *driver,
virObjectUnlock(driver);
if (olddom) {
- virDomainDefFree(def);
return olddom;
} else if (!dom) {
goto error;
@@ -1898,7 +1897,7 @@ prlsdkLoadDomain(struct _vzDriver *driver,
* we can't use virDomainObjAssignDef, because it checks
* for state and domain name */
virDomainDefFree(dom->def);
- dom->def = def;
+ dom->def = g_steal_pointer(&def);
}
pdom = dom->privateData;
@@ -1914,7 +1913,6 @@ prlsdkLoadDomain(struct _vzDriver *driver,
return dom;
error:
- virDomainDefFree(def);
return NULL;
}
diff --git a/tests/securityselinuxtest.c b/tests/securityselinuxtest.c
index 119ad6df34..4912cc3483 100644
--- a/tests/securityselinuxtest.c
+++ b/tests/securityselinuxtest.c
@@ -64,7 +64,7 @@ testBuildDomainDef(bool dynamic,
const char *label,
const char *baselabel)
{
- virDomainDef *def;
+ g_autoptr(virDomainDef) def = NULL;
virSecurityLabelDef *secdef = NULL;
if (!(def = virDomainDefNew(NULL)))
@@ -86,10 +86,9 @@ testBuildDomainDef(bool dynamic,
def->seclabels[0] = secdef;
def->nseclabels++;
- return def;
+ return g_steal_pointer(&def);
error:
- virDomainDefFree(def);
virSecurityLabelDefFree(secdef);
return NULL;
}
@@ -211,7 +210,7 @@ testSELinuxGenLabel(const void *opaque)
{
const struct testSELinuxGenLabelData *data = opaque;
int ret = -1;
- virDomainDef *def;
+ g_autoptr(virDomainDef) def = NULL;
context_t con = NULL;
context_t imgcon = NULL;
@@ -255,7 +254,6 @@ testSELinuxGenLabel(const void *opaque)
cleanup:
context_free(con);
context_free(imgcon);
- virDomainDefFree(def);
return ret;
}
--
2.32.0