Signed-off-by: Rafael Fonseca <r4f4rfs(a)gmail.com>
---
src/bhyve/bhyve_driver.c | 3 ++-
src/conf/domain_conf.c | 29 +++++++++++++++++++----------
src/conf/domain_conf.h | 9 +++++++++
src/esx/esx_driver.c | 3 ++-
src/libxl/libxl_driver.c | 3 ++-
src/lxc/lxc_controller.c | 3 ++-
src/lxc/lxc_driver.c | 3 ++-
src/openvz/openvz_conf.c | 3 ++-
src/qemu/qemu_driver.c | 3 ++-
src/qemu/qemu_process.c | 15 +++++----------
src/security/virt-aa-helper.c | 3 ++-
src/test/test_driver.c | 3 ++-
src/vbox/vbox_common.c | 3 ++-
src/vmware/vmware_conf.c | 3 ++-
src/vz/vz_driver.c | 3 ++-
tests/bhyveargv2xmltest.c | 2 +-
tests/bhyvexml2argvtest.c | 2 +-
tests/bhyvexml2xmltest.c | 2 +-
tests/domainconftest.c | 3 ++-
tests/genericxml2xmltest.c | 3 ++-
tests/openvzutilstest.c | 2 +-
tests/testutilslxc.c | 3 ++-
tests/testutilsqemu.c | 3 ++-
tests/testutilsxen.c | 3 ++-
tests/vmx2xmltest.c | 3 ++-
tests/xml2vmxtest.c | 6 ++++--
26 files changed, 77 insertions(+), 44 deletions(-)
diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index 4ca3666700..2224395128 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -1183,7 +1183,8 @@ bhyveStateCleanup(void)
virObjectUnref(bhyve_driver->domains);
if (bhyve_driver->caps)
g_object_unref(bhyve_driver->caps);
- virObjectUnref(bhyve_driver->xmlopt);
+ if (bhyve_driver->xmlopt)
+ g_object_unref(bhyve_driver->xmlopt);
virSysinfoDefFree(bhyve_driver->hostsysinfo);
virObjectUnref(bhyve_driver->closeCallbacks);
virObjectUnref(bhyve_driver->domainEventState);
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 425a6bccb6..38a0c04c1f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -71,7 +71,7 @@ VIR_LOG_INIT("conf.domain_conf");
/* This structure holds various callbacks and data needed
* while parsing and creating domain XMLs */
struct _virDomainXMLOption {
- virObject parent;
+ GObject parent;
/* XML parser callbacks and defaults */
virDomainDefParserConfig config;
@@ -1273,18 +1273,26 @@ VIR_ENUM_IMPL(virDomainLaunchSecurity,
);
static virClassPtr virDomainObjClass;
-static virClassPtr virDomainXMLOptionClass;
static void virDomainObjDispose(void *obj);
-static void virDomainXMLOptionDispose(void *obj);
+G_DEFINE_TYPE(virDomainXMLOption, vir_domain_xml_option, G_TYPE_OBJECT);
+static void virDomainXMLOptionFinalize(GObject *obj);
+
+static void vir_domain_xml_option_init(virDomainXMLOption *option G_GNUC_UNUSED)
+{
+}
+
+static void vir_domain_xml_option_class_init(virDomainXMLOptionClass *klass)
+{
+ GObjectClass *obj = G_OBJECT_CLASS(klass);
+
+ obj->finalize = virDomainXMLOptionFinalize;
+}
static int virDomainObjOnceInit(void)
{
if (!VIR_CLASS_NEW(virDomainObj, virClassForObjectLockable()))
return -1;
- if (!VIR_CLASS_NEW(virDomainXMLOption, virClassForObject()))
- return -1;
-
return 0;
}
@@ -1292,12 +1300,14 @@ VIR_ONCE_GLOBAL_INIT(virDomainObj);
static void
-virDomainXMLOptionDispose(void *obj)
+virDomainXMLOptionFinalize(GObject *obj)
{
- virDomainXMLOptionPtr xmlopt = obj;
+ virDomainXMLOptionPtr xmlopt = VIR_DOMAIN_XML_OPTION(obj);
if (xmlopt->config.privFree)
(xmlopt->config.privFree)(xmlopt->config.priv);
+
+ G_OBJECT_CLASS(vir_domain_xml_option_parent_class)->finalize(obj);
}
/**
@@ -1424,8 +1434,7 @@ virDomainXMLOptionNew(virDomainDefParserConfigPtr config,
if (virDomainObjInitialize() < 0)
return NULL;
- if (!(xmlopt = virObjectNew(virDomainXMLOptionClass)))
- return NULL;
+ xmlopt = VIR_DOMAIN_XML_OPTION(g_object_new(VIR_TYPE_DOMAIN_XML_OPTION, NULL));
if (priv)
xmlopt->privateData = *priv;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 33875d942f..7e2792ae62 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -58,6 +58,8 @@
#include "virresctrl.h"
#include "virenum.h"
+#include <glib-object.h>
+
/* Flags for the 'type' field in virDomainDeviceDef */
typedef enum {
VIR_DOMAIN_DEVICE_NONE = 0,
@@ -2800,6 +2802,13 @@ struct _virDomainABIStability {
virDomainABIStabilityDomain domain;
};
+#define VIR_TYPE_DOMAIN_XML_OPTION vir_domain_xml_option_get_type()
+G_DECLARE_FINAL_TYPE(virDomainXMLOption,
+ vir_domain_xml_option,
+ VIR,
+ DOMAIN_XML_OPTION,
+ GObject);
+
virDomainXMLOptionPtr virDomainXMLOptionNew(virDomainDefParserConfigPtr config,
virDomainXMLPrivateDataCallbacksPtr priv,
virXMLNamespacePtr xmlns,
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index f893d112d0..354f5cbe69 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -71,7 +71,8 @@ esxFreePrivate(esxPrivate **priv)
esxUtil_FreeParsedUri(&(*priv)->parsedUri);
if ((*priv)->caps)
g_object_unref((*priv)->caps);
- virObjectUnref((*priv)->xmlopt);
+ if ((*priv)->xmlopt)
+ g_object_unref((*priv)->xmlopt);
VIR_FREE(*priv);
}
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 7ec4fcc3d1..6564b45ee4 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -507,7 +507,8 @@ libxlStateCleanup(void)
return -1;
virObjectUnref(libxl_driver->hostdevMgr);
- virObjectUnref(libxl_driver->xmlopt);
+ if (libxl_driver->xmlopt)
+ g_object_unref(libxl_driver->xmlopt);
virObjectUnref(libxl_driver->domains);
virPortAllocatorRangeFree(libxl_driver->reservedGraphicsPorts);
virPortAllocatorRangeFree(libxl_driver->migrationPorts);
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 2369704ac6..4c038c6228 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -180,7 +180,8 @@ virLXCControllerDriverFree(virLXCDriverPtr driver)
{
if (!driver)
return;
- virObjectUnref(driver->xmlopt);
+ if (driver->xmlopt)
+ g_object_unref(driver->xmlopt);
if (driver->caps)
g_object_unref(driver->caps);
virMutexDestroy(&driver->lock);
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 1c59ddef6d..5da9ec7c58 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -1614,7 +1614,8 @@ static int lxcStateCleanup(void)
if (lxc_driver->caps)
g_object_unref(lxc_driver->caps);
virObjectUnref(lxc_driver->securityManager);
- virObjectUnref(lxc_driver->xmlopt);
+ if (lxc_driver->xmlopt)
+ g_object_unref(lxc_driver->xmlopt);
if (lxc_driver->lockFD != -1)
virPidFileRelease(lxc_driver->config->stateDir, "driver",
lxc_driver->lockFD);
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index 1f70bfc3d9..a62e536aa0 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -479,7 +479,8 @@ openvzFreeDriver(struct openvz_driver *driver)
if (!driver)
return;
- virObjectUnref(driver->xmlopt);
+ if (driver->xmlopt)
+ g_object_unref(driver->xmlopt);
virObjectUnref(driver->domains);
if (driver->caps)
g_object_unref(driver->caps);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 99a5058033..73f1037e8a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1131,7 +1131,8 @@ qemuStateCleanup(void)
virObjectUnref(qemu_driver->securityManager);
virObjectUnref(qemu_driver->domainEventState);
virObjectUnref(qemu_driver->qemuCapsCache);
- virObjectUnref(qemu_driver->xmlopt);
+ if (qemu_driver->xmlopt)
+ g_object_unref(qemu_driver->xmlopt);
virCPUDefFree(qemu_driver->hostcpu);
virCapabilitiesHostNUMAUnref(qemu_driver->hostnuma);
if (qemu_driver->caps)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 3f28c5245c..ef34dd8cfd 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -8567,9 +8567,8 @@ qemuProcessQMPInitMonitor(qemuMonitorPtr mon)
static int
qemuProcessQMPConnectMonitor(qemuProcessQMPPtr proc)
{
- virDomainXMLOptionPtr xmlopt = NULL;
+ g_autoptr(virDomainXMLOption) xmlopt = NULL;
virDomainChrSourceDef monConfig;
- int ret = -1;
VIR_DEBUG("proc=%p, emulator=%s, proc->pid=%lld",
proc, proc->binary, (long long)proc->pid);
@@ -8581,25 +8580,21 @@ qemuProcessQMPConnectMonitor(qemuProcessQMPPtr proc)
if (!(xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL, NULL, NULL)) ||
!(proc->vm = virDomainObjNew(xmlopt)) ||
!(proc->vm->def = virDomainDefNew()))
- goto cleanup;
+ return -1;
proc->vm->pid = proc->pid;
if (!(proc->mon = qemuMonitorOpen(proc->vm, &monConfig, true, 0,
virEventThreadGetContext(proc->eventThread),
&callbacks, NULL)))
- goto cleanup;
+ return -1;
virObjectLock(proc->mon);
if (qemuProcessQMPInitMonitor(proc->mon) < 0)
- goto cleanup;
-
- ret = 0;
+ return -1;
- cleanup:
- virObjectUnref(xmlopt);
- return ret;
+ return 0;
}
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c
index 7b0ae6acad..cbf4a567d5 100644
--- a/src/security/virt-aa-helper.c
+++ b/src/security/virt-aa-helper.c
@@ -81,7 +81,8 @@ vahDeinit(vahControl * ctl)
VIR_FREE(ctl->def);
if (ctl->caps)
g_object_unref(ctl->caps);
- virObjectUnref(ctl->xmlopt);
+ if (ctl->xmlopt)
+ g_object_unref(ctl->xmlopt);
VIR_FREE(ctl->files);
VIR_FREE(ctl->virtType);
VIR_FREE(ctl->os);
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 00c3d34a81..1696b956fe 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -160,7 +160,8 @@ testDriverDispose(void *obj)
if (driver->caps)
g_object_unref(driver->caps);
- virObjectUnref(driver->xmlopt);
+ if (driver->xmlopt)
+ g_object_unref(driver->xmlopt);
virObjectUnref(driver->domains);
virNodeDeviceObjListFree(driver->devs);
virObjectUnref(driver->networks);
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 0e009a5739..60018668ca 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -124,7 +124,8 @@ vboxDriverDispose(void *obj)
if (driver->caps)
g_object_unref(driver->caps);
- virObjectUnref(driver->xmlopt);
+ if (driver->xmlopt)
+ g_object_unref(driver->xmlopt);
}
static int
diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c
index ee21e96971..e5e3ee33a5 100644
--- a/src/vmware/vmware_conf.c
+++ b/src/vmware/vmware_conf.c
@@ -56,7 +56,8 @@ vmwareFreeDriver(struct vmware_driver *driver)
virObjectUnref(driver->domains);
if (driver->caps)
g_object_unref(driver->caps);
- virObjectUnref(driver->xmlopt);
+ if (driver->xmlopt)
+ g_object_unref(driver->xmlopt);
VIR_FREE(driver->vmrun);
VIR_FREE(driver);
}
diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index 517259131d..ab06071731 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -150,7 +150,8 @@ static void vzDriverDispose(void * obj)
virObjectUnref(driver->domains);
if (driver->caps)
g_object_unref(driver->caps);
- virObjectUnref(driver->xmlopt);
+ if (driver->xmlopt)
+ g_object_unref(driver->xmlopt);
virObjectUnref(driver->domainEventState);
virSysinfoDefFree(driver->hostsysinfo);
}
diff --git a/tests/bhyveargv2xmltest.c b/tests/bhyveargv2xmltest.c
index 5de5b48a8e..3cc6ca8b38 100644
--- a/tests/bhyveargv2xmltest.c
+++ b/tests/bhyveargv2xmltest.c
@@ -196,7 +196,7 @@ mymain(void)
DO_TEST_FAIL("extraargs");
g_object_unref(driver.caps);
- virObjectUnref(driver.xmlopt);
+ g_object_unref(driver.xmlopt);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c
index 9ea0d76f06..48abb436d0 100644
--- a/tests/bhyvexml2argvtest.c
+++ b/tests/bhyvexml2argvtest.c
@@ -250,7 +250,7 @@ mymain(void)
DO_TEST_FAILURE("cputopology");
g_object_unref(driver.caps);
- virObjectUnref(driver.xmlopt);
+ g_object_unref(driver.xmlopt);
virPortAllocatorRangeFree(driver.remotePorts);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
diff --git a/tests/bhyvexml2xmltest.c b/tests/bhyvexml2xmltest.c
index cb0f6022c3..add96d4859 100644
--- a/tests/bhyvexml2xmltest.c
+++ b/tests/bhyvexml2xmltest.c
@@ -128,7 +128,7 @@ mymain(void)
DO_TEST_DIFFERENT("input-xhci-tablet");
g_object_unref(driver.caps);
- virObjectUnref(driver.xmlopt);
+ g_object_unref(driver.xmlopt);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
diff --git a/tests/domainconftest.c b/tests/domainconftest.c
index ada397b925..c19da1ae97 100644
--- a/tests/domainconftest.c
+++ b/tests/domainconftest.c
@@ -105,7 +105,8 @@ mymain(void)
if (caps)
g_object_unref(caps);
- virObjectUnref(xmlopt);
+ if (xmlopt)
+ g_object_unref(xmlopt);
cleanup:
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
diff --git a/tests/genericxml2xmltest.c b/tests/genericxml2xmltest.c
index 0659ca1b28..339d1478a3 100644
--- a/tests/genericxml2xmltest.c
+++ b/tests/genericxml2xmltest.c
@@ -197,7 +197,8 @@ mymain(void)
if (caps)
g_object_unref(caps);
- virObjectUnref(xmlopt);
+ if (xmlopt)
+ g_object_unref(xmlopt);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
diff --git a/tests/openvzutilstest.c b/tests/openvzutilstest.c
index 48de2d1c7d..2fd21fc718 100644
--- a/tests/openvzutilstest.c
+++ b/tests/openvzutilstest.c
@@ -131,7 +131,7 @@ testReadNetworkConf(const void *data G_GNUC_UNUSED)
result = 0;
cleanup:
- virObjectUnref(driver.xmlopt);
+ g_object_unref(driver.xmlopt);
g_object_unref(driver.caps);
VIR_FREE(actual);
virDomainDefFree(def);
diff --git a/tests/testutilslxc.c b/tests/testutilslxc.c
index 2f28975332..ad2afdd683 100644
--- a/tests/testutilslxc.c
+++ b/tests/testutilslxc.c
@@ -76,7 +76,8 @@ testLXCDriverInit(void)
void
testLXCDriverFree(virLXCDriverPtr driver)
{
- virObjectUnref(driver->xmlopt);
+ if (driver->xmlopt)
+ g_object_unref(driver->xmlopt);
if (driver->caps)
g_object_unref(driver->caps);
virMutexDestroy(&driver->lock);
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index dd8143ff55..a37865bc14 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -307,7 +307,8 @@ void qemuTestDriverFree(virQEMUDriver *driver)
virFileDeleteTree(driver->config->configDir);
}
virObjectUnref(driver->qemuCapsCache);
- virObjectUnref(driver->xmlopt);
+ if (driver->xmlopt)
+ g_object_unref(driver->xmlopt);
if (driver->caps)
g_object_unref(driver->caps);
virObjectUnref(driver->config);
diff --git a/tests/testutilsxen.c b/tests/testutilsxen.c
index 7da90cdd1e..6b6b0bf038 100644
--- a/tests/testutilsxen.c
+++ b/tests/testutilsxen.c
@@ -112,7 +112,8 @@ libxlDriverPrivatePtr testXLInitDriver(void)
void testXLFreeDriver(libxlDriverPrivatePtr driver)
{
virObjectUnref(driver->config);
- virObjectUnref(driver->xmlopt);
+ if (driver->xmlopt)
+ g_object_unref(driver->xmlopt);
virMutexDestroy(&driver->lock);
g_free(driver);
}
diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c
index b5c557fe33..c87b60fc78 100644
--- a/tests/vmx2xmltest.c
+++ b/tests/vmx2xmltest.c
@@ -282,7 +282,8 @@ mymain(void)
DO_TEST("datacenterpath", "datacenterpath");
g_object_unref(caps);
- virObjectUnref(xmlopt);
+ if (xmlopt)
+ g_object_unref(xmlopt);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c
index d6c7eb4f53..735df01e56 100644
--- a/tests/xml2vmxtest.c
+++ b/tests/xml2vmxtest.c
@@ -61,7 +61,8 @@ testCapsInit(void)
failure:
if (caps)
g_clear_object(&caps);
- virObjectUnref(xmlopt);
+ if (xmlopt)
+ g_object_unref(xmlopt);
}
static int
@@ -292,7 +293,8 @@ mymain(void)
DO_TEST("datacenterpath", "datacenterpath", 4);
g_object_unref(caps);
- virObjectUnref(xmlopt);
+ if (xmlopt)
+ g_object_unref(xmlopt);
return result == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
--
2.25.1