[PATCH v2 33/40] libxl: convert libxlDriverConfig to GObject

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Rafael Fonseca <r4f4rfs@xxxxxxxxx>
---
 src/libxl/libxl_conf.c      |  62 ++++++++------
 src/libxl/libxl_conf.h      |  12 ++-
 src/libxl/libxl_driver.c    | 162 ++++++++++++------------------------
 src/libxl/libxl_migration.c |  21 ++---
 tests/testutilsxen.c        |   2 +-
 5 files changed, 107 insertions(+), 152 deletions(-)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index be37e0835d..9ea4e1c941 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -52,25 +52,40 @@
 VIR_LOG_INIT("libxl.libxl_conf");
 
 
-static virClassPtr libxlDriverConfigClass;
-static void libxlDriverConfigDispose(void *obj);
+G_DEFINE_TYPE(libxlDriverConfig, libxl_driver_config, G_TYPE_OBJECT);
 
-static int libxlConfigOnceInit(void)
-{
-    if (!VIR_CLASS_NEW(libxlDriverConfig, virClassForObject()))
-        return -1;
+static void libxlDriverConfigDispose(GObject *obj);
+static void libxlDriverConfigFinalize(GObject *obj);
 
-    return 0;
+static void
+libxl_driver_config_init(libxlDriverConfig *cfg G_GNUC_UNUSED)
+{
 }
 
-VIR_ONCE_GLOBAL_INIT(libxlConfig);
+static void
+libxl_driver_config_class_init(libxlDriverConfigClass *klass)
+{
+    GObjectClass *obj = G_OBJECT_CLASS(klass);
+
+    obj->dispose = libxlDriverConfigDispose;
+    obj->finalize = libxlDriverConfigFinalize;
+}
 
 static void
-libxlDriverConfigDispose(void *obj)
+libxlDriverConfigDispose(GObject *obj)
 {
-    libxlDriverConfigPtr cfg = obj;
+    libxlDriverConfigPtr cfg = LIBXL_DRIVER_CONFIG(obj);
 
     g_clear_object(&cfg->caps);
+
+    G_OBJECT_CLASS(libxl_driver_config_parent_class)->dispose(obj);
+}
+
+static void
+libxlDriverConfigFinalize(GObject *obj)
+{
+    libxlDriverConfigPtr cfg = LIBXL_DRIVER_CONFIG(obj);
+
     libxl_ctx_free(cfg->ctx);
     if (cfg->logger)
         libxlLoggerFree(cfg->logger);
@@ -86,6 +101,8 @@ libxlDriverConfigDispose(void *obj)
     VIR_FREE(cfg->lockManagerName);
     VIR_FREE(cfg->channelDir);
     virFirmwareFreeList(cfg->firmwares, cfg->nfirmwares);
+
+    G_OBJECT_CLASS(libxl_driver_config_parent_class)->finalize(obj);
 }
 
 
@@ -1688,13 +1705,8 @@ libxlGetAutoballoonConf(libxlDriverConfigPtr cfg,
 libxlDriverConfigPtr
 libxlDriverConfigNew(void)
 {
-    libxlDriverConfigPtr cfg;
-
-    if (libxlConfigInitialize() < 0)
-        return NULL;
-
-    if (!(cfg = virObjectNew(libxlDriverConfigClass)))
-        return NULL;
+    g_autoptr(libxlDriverConfig) cfg =
+        LIBXL_DRIVER_CONFIG(g_object_new(LIBXL_TYPE_DRIVER_CONFIG, NULL));
 
     cfg->configBaseDir = g_strdup(LIBXL_CONFIG_BASE_DIR);
     cfg->configDir = g_strdup(LIBXL_CONFIG_DIR);
@@ -1710,34 +1722,30 @@ libxlDriverConfigNew(void)
     if (virFirmwareParseList(DEFAULT_LOADER_NVRAM,
                              &cfg->firmwares,
                              &cfg->nfirmwares) < 0)
-        goto error;
+        return NULL;
 
 #else
     if (VIR_ALLOC_N(cfg->firmwares, 1) < 0)
-        goto error;
+        return NULL;
     cfg->nfirmwares = 1;
     if (VIR_ALLOC(cfg->firmwares[0]) < 0)
-        goto error;
+        return NULL;
     cfg->firmwares[0]->name = g_strdup(LIBXL_FIRMWARE_DIR "/ovmf.bin");
 #endif
 
     /* Always add hvmloader to firmwares */
     if (VIR_REALLOC_N(cfg->firmwares, cfg->nfirmwares + 1) < 0)
-        goto error;
+        return NULL;
     cfg->nfirmwares++;
     if (VIR_ALLOC(cfg->firmwares[cfg->nfirmwares - 1]) < 0)
-        goto error;
+        return NULL;
     cfg->firmwares[cfg->nfirmwares - 1]->name = g_strdup(LIBXL_FIRMWARE_DIR "/hvmloader");
 
     /* defaults for keepalive messages */
     cfg->keepAliveInterval = 5;
     cfg->keepAliveCount = 5;
 
-    return cfg;
-
- error:
-    virObjectUnref(cfg);
-    return NULL;
+    return g_steal_pointer(&cfg);
 }
 
 int
diff --git a/src/libxl/libxl_conf.h b/src/libxl/libxl_conf.h
index 07b3373170..94386cc8cc 100644
--- a/src/libxl/libxl_conf.h
+++ b/src/libxl/libxl_conf.h
@@ -37,6 +37,7 @@
 #include "virfirmware.h"
 #include "libxl_capabilities.h"
 #include "libxl_logger.h"
+#include <glib-object.h>
 
 #define LIBXL_DRIVER_NAME "xenlight"
 #define LIBXL_VNC_PORT_MIN  5900
@@ -60,11 +61,17 @@
 typedef struct _libxlDriverPrivate libxlDriverPrivate;
 typedef libxlDriverPrivate *libxlDriverPrivatePtr;
 
-typedef struct _libxlDriverConfig libxlDriverConfig;
+#define LIBXL_TYPE_DRIVER_CONFIG libxl_driver_config_get_type()
+G_DECLARE_FINAL_TYPE(libxlDriverConfig,
+                     libxl_driver_config,
+                     LIBXL,
+                     DRIVER_CONFIG,
+                     GObject);
+
 typedef libxlDriverConfig *libxlDriverConfigPtr;
 
 struct _libxlDriverConfig {
-    virObject parent;
+    GObject parent;
 
     const libxl_version_info *verInfo;
     unsigned int version;
@@ -102,7 +109,6 @@ struct _libxlDriverConfig {
     size_t nfirmwares;
 };
 
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(libxlDriverConfig, virObjectUnref);
 
 
 struct _libxlDriverPrivate {
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 0e4d6c56fc..affae0e86e 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -390,7 +390,7 @@ libxlReconnectDomain(virDomainObjPtr vm,
 {
     libxlDriverPrivatePtr driver = opaque;
     libxlDomainObjPrivatePtr priv = vm->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     int rc;
     libxl_dominfo d_info;
     int len;
@@ -484,7 +484,6 @@ libxlReconnectDomain(virDomainObjPtr vm,
     libxl_dominfo_dispose(&d_info);
     virObjectUnlock(vm);
     virObjectUnref(vm);
-    virObjectUnref(cfg);
     return ret;
 
  error:
@@ -519,7 +518,7 @@ libxlStateCleanup(void)
     if (libxl_driver->lockFD != -1)
         virPidFileRelease(libxl_driver->config->stateDir, "driver", libxl_driver->lockFD);
 
-    virObjectUnref(libxl_driver->config);
+    g_clear_object(&libxl_driver->config);
     virMutexDestroy(&libxl_driver->lock);
     VIR_FREE(libxl_driver);
 
@@ -589,7 +588,7 @@ const struct libxl_event_hooks ev_hooks = {
 static int
 libxlAddDom0(libxlDriverPrivatePtr driver)
 {
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainDefPtr def = NULL;
     virDomainObjPtr vm = NULL;
     libxl_dominfo d_info;
@@ -642,7 +641,6 @@ libxlAddDom0(libxlDriverPrivatePtr driver)
     libxl_dominfo_dispose(&d_info);
     virDomainDefFree(def);
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -831,7 +829,7 @@ libxlStateInitialize(bool privileged,
 static int
 libxlStateReload(void)
 {
-    libxlDriverConfigPtr cfg;
+    g_autoptr(libxlDriverConfig) cfg = NULL;
 
     if (!libxl_driver)
         return 0;
@@ -849,7 +847,6 @@ libxlStateReload(void)
                             libxlAutostartDomain,
                             libxl_driver);
 
-    virObjectUnref(cfg);
     return 0;
 }
 
@@ -918,14 +915,13 @@ static int
 libxlConnectGetVersion(virConnectPtr conn, unsigned long *version)
 {
     libxlDriverPrivatePtr driver = conn->privateData;
-    libxlDriverConfigPtr cfg;
+    g_autoptr(libxlDriverConfig) cfg = NULL;
 
     if (virConnectGetVersionEnsureACL(conn) < 0)
         return 0;
 
     cfg = libxlDriverConfigGet(driver);
     *version = cfg->version;
-    virObjectUnref(cfg);
     return 0;
 }
 
@@ -965,7 +961,7 @@ libxlConnectGetMaxVcpus(virConnectPtr conn, const char *type G_GNUC_UNUSED)
 {
     int ret;
     libxlDriverPrivatePtr driver = conn->privateData;
-    libxlDriverConfigPtr cfg;
+    g_autoptr(libxlDriverConfig) cfg = NULL;
 
     if (virConnectGetMaxVcpusEnsureACL(conn) < 0)
         return -1;
@@ -979,7 +975,6 @@ libxlConnectGetMaxVcpus(virConnectPtr conn, const char *type G_GNUC_UNUSED)
     if (ret <= 0)
         ret = -1;
 
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -997,7 +992,7 @@ libxlConnectGetCapabilities(virConnectPtr conn)
 {
     libxlDriverPrivatePtr driver = conn->privateData;
     char *xml;
-    libxlDriverConfigPtr cfg;
+    g_autoptr(libxlDriverConfig) cfg = NULL;
 
     if (virConnectGetCapabilitiesEnsureACL(conn) < 0)
         return NULL;
@@ -1005,7 +1000,6 @@ libxlConnectGetCapabilities(virConnectPtr conn)
     cfg = libxlDriverConfigGet(driver);
     xml = virCapabilitiesFormatXML(cfg->caps);
 
-    virObjectUnref(cfg);
     return xml;
 }
 
@@ -1041,7 +1035,7 @@ libxlDomainCreateXML(virConnectPtr conn, const char *xml,
     virDomainDefPtr def;
     virDomainObjPtr vm = NULL;
     virDomainPtr dom = NULL;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
 
     virCheckFlags(VIR_DOMAIN_START_PAUSED |
@@ -1086,7 +1080,6 @@ libxlDomainCreateXML(virConnectPtr conn, const char *xml,
  cleanup:
     virDomainDefFree(def);
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return dom;
 }
 
@@ -1163,7 +1156,7 @@ static int
 libxlDomainSuspend(virDomainPtr dom)
 {
     libxlDriverPrivatePtr driver = dom->conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainObjPtr vm;
     virObjectEventPtr event = NULL;
     int ret = -1;
@@ -1207,7 +1200,6 @@ libxlDomainSuspend(virDomainPtr dom)
  cleanup:
     virDomainObjEndAPI(&vm);
     virObjectEventStateQueue(driver->domainEventState, event);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -1216,7 +1208,7 @@ static int
 libxlDomainResume(virDomainPtr dom)
 {
     libxlDriverPrivatePtr driver = dom->conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainObjPtr vm;
     virObjectEventPtr event = NULL;
     int ret = -1;
@@ -1261,7 +1253,6 @@ libxlDomainResume(virDomainPtr dom)
  cleanup:
     virDomainObjEndAPI(&vm);
     virObjectEventStateQueue(driver->domainEventState, event);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -1269,7 +1260,7 @@ static int
 libxlDomainShutdownFlags(virDomainPtr dom, unsigned int flags)
 {
     libxlDriverPrivatePtr driver = dom->conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainObjPtr vm;
     int ret = -1;
 
@@ -1319,7 +1310,6 @@ libxlDomainShutdownFlags(virDomainPtr dom, unsigned int flags)
 
  cleanup:
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -1334,7 +1324,7 @@ static int
 libxlDomainReboot(virDomainPtr dom, unsigned int flags)
 {
     libxlDriverPrivatePtr driver = dom->conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainObjPtr vm;
     int ret = -1;
 
@@ -1366,7 +1356,6 @@ libxlDomainReboot(virDomainPtr dom, unsigned int flags)
 
  cleanup:
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -1375,7 +1364,7 @@ libxlDomainDestroyFlags(virDomainPtr dom,
                         unsigned int flags)
 {
     libxlDriverPrivatePtr driver = dom->conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainObjPtr vm;
     int ret = -1;
     virObjectEventPtr event = NULL;
@@ -1420,7 +1409,6 @@ libxlDomainDestroyFlags(virDomainPtr dom,
  cleanup:
     virDomainObjEndAPI(&vm);
     virObjectEventStateQueue(driver->domainEventState, event);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -1440,7 +1428,7 @@ libxlDomainPMSuspendForDuration(virDomainPtr dom,
     virDomainObjPtr vm;
     int ret = -1;
     libxlDriverPrivatePtr driver = dom->conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virObjectEventPtr event = NULL;
 
     virCheckFlags(0, -1);
@@ -1506,7 +1494,7 @@ libxlDomainPMWakeup(virDomainPtr dom, unsigned int flags)
     int ret = -1;
     virObjectEventPtr event = NULL;
     libxlDomainObjPrivatePtr priv;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
 
     virCheckFlags(0, -1);
 
@@ -1635,7 +1623,7 @@ libxlDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
                           unsigned int flags)
 {
     libxlDriverPrivatePtr driver = dom->conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainObjPtr vm;
     virDomainDefPtr persistentDef = NULL;
     int ret = -1;
@@ -1720,7 +1708,6 @@ libxlDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
 
  cleanup:
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -1740,7 +1727,7 @@ static int
 libxlDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info)
 {
     libxlDriverPrivatePtr driver = dom->conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainObjPtr vm;
     libxl_dominfo d_info;
     int ret = -1;
@@ -1776,7 +1763,6 @@ libxlDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info)
 
  cleanup:
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -1814,7 +1800,7 @@ libxlDoDomainSave(libxlDriverPrivatePtr driver,
                   const char *to,
                   bool managed)
 {
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     libxlSavefileHeader hdr;
     virObjectEventPtr event = NULL;
     char *xml = NULL;
@@ -1891,7 +1877,6 @@ libxlDoDomainSave(libxlDriverPrivatePtr driver,
     if (VIR_CLOSE(fd) < 0)
         virReportSystemError(errno, "%s", _("cannot close file"));
     virObjectEventStateQueue(driver->domainEventState, event);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -1956,7 +1941,7 @@ libxlDomainRestoreFlags(virConnectPtr conn, const char *from,
                         const char *dxml, unsigned int flags)
 {
     libxlDriverPrivatePtr driver = conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainObjPtr vm = NULL;
     virDomainDefPtr def = NULL;
     libxlSavefileHeader hdr;
@@ -2009,7 +1994,6 @@ libxlDomainRestoreFlags(virConnectPtr conn, const char *from,
         virReportSystemError(errno, "%s", _("cannot close file"));
     virDomainDefFree(def);
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -2023,7 +2007,7 @@ static int
 libxlDomainCoreDump(virDomainPtr dom, const char *to, unsigned int flags)
 {
     libxlDriverPrivatePtr driver = dom->conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainObjPtr vm;
     virObjectEventPtr event = NULL;
     bool paused = false;
@@ -2106,7 +2090,6 @@ libxlDomainCoreDump(virDomainPtr dom, const char *to, unsigned int flags)
  cleanup:
     virDomainObjEndAPI(&vm);
     virObjectEventStateQueue(driver->domainEventState, event);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -2239,7 +2222,7 @@ libxlDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
                          unsigned int flags)
 {
     libxlDriverPrivatePtr driver = dom->conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainDefPtr def;
     virDomainObjPtr vm;
     libxl_bitmap map;
@@ -2377,7 +2360,6 @@ libxlDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
  cleanup:
     VIR_FREE(bitmask);
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -2458,7 +2440,7 @@ libxlDomainPinVcpuFlags(virDomainPtr dom, unsigned int vcpu,
                         unsigned int flags)
 {
     libxlDriverPrivatePtr driver = dom->conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainDefPtr targetDef = NULL;
     virBitmapPtr pcpumap = NULL;
     virDomainVcpuDefPtr vcpuinfo;
@@ -2526,7 +2508,6 @@ libxlDomainPinVcpuFlags(virDomainPtr dom, unsigned int vcpu,
  cleanup:
     virDomainObjEndAPI(&vm);
     virBitmapFree(pcpumap);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -2544,7 +2525,7 @@ libxlDomainGetVcpuPinInfo(virDomainPtr dom, int ncpumaps,
                           unsigned int flags)
 {
     libxlDriverPrivatePtr driver = dom->conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainObjPtr vm = NULL;
     virDomainDefPtr targetDef = NULL;
     int ret = -1;
@@ -2573,7 +2554,6 @@ libxlDomainGetVcpuPinInfo(virDomainPtr dom, int ncpumaps,
 
  cleanup:
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -2582,7 +2562,7 @@ libxlDomainGetVcpus(virDomainPtr dom, virVcpuInfoPtr info, int maxinfo,
                     unsigned char *cpumaps, int maplen)
 {
     libxlDriverPrivatePtr driver = dom->conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainObjPtr vm;
     int ret = -1;
     libxl_vcpuinfo *vcpuinfo;
@@ -2634,7 +2614,6 @@ libxlDomainGetVcpus(virDomainPtr dom, virVcpuInfoPtr info, int maxinfo,
 
  cleanup:
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -2642,7 +2621,7 @@ static char *
 libxlDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
 {
     libxlDriverPrivatePtr driver = dom->conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainObjPtr vm;
     virDomainDefPtr def;
     char *ret = NULL;
@@ -2665,7 +2644,6 @@ libxlDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
 
  cleanup:
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -2676,7 +2654,7 @@ libxlConnectDomainXMLFromNative(virConnectPtr conn,
                                 unsigned int flags)
 {
     libxlDriverPrivatePtr driver = conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainDefPtr def = NULL;
     g_autoptr(virConf) conf = NULL;
     char *xml = NULL;
@@ -2715,7 +2693,6 @@ libxlConnectDomainXMLFromNative(virConnectPtr conn,
 
  cleanup:
     virDomainDefFree(def);
-    virObjectUnref(cfg);
     return xml;
 }
 
@@ -2726,7 +2703,7 @@ libxlConnectDomainXMLToNative(virConnectPtr conn, const char * nativeFormat,
                               unsigned int flags)
 {
     libxlDriverPrivatePtr driver = conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainDefPtr def = NULL;
     g_autoptr(virConf) conf = NULL;
     int len = MAX_CONFIG_SIZE;
@@ -2765,7 +2742,6 @@ libxlConnectDomainXMLToNative(virConnectPtr conn, const char * nativeFormat,
 
  cleanup:
     virDomainDefFree(def);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -2845,7 +2821,7 @@ static virDomainPtr
 libxlDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
 {
     libxlDriverPrivatePtr driver = conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainDefPtr def = NULL;
     virDomainObjPtr vm = NULL;
     virDomainPtr dom = NULL;
@@ -2895,7 +2871,6 @@ libxlDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flag
     virDomainDefFree(oldDef);
     virDomainObjEndAPI(&vm);
     virObjectEventStateQueue(driver->domainEventState, event);
-    virObjectUnref(cfg);
     return dom;
 }
 
@@ -2910,7 +2885,7 @@ libxlDomainUndefineFlags(virDomainPtr dom,
                          unsigned int flags)
 {
     libxlDriverPrivatePtr driver = dom->conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainObjPtr vm;
     virObjectEventPtr event = NULL;
     char *name = NULL;
@@ -2966,7 +2941,6 @@ libxlDomainUndefineFlags(virDomainPtr dom,
     VIR_FREE(name);
     virDomainObjEndAPI(&vm);
     virObjectEventStateQueue(driver->domainEventState, event);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -2979,7 +2953,7 @@ libxlDomainUndefine(virDomainPtr dom)
 static int
 libxlDomainChangeEjectableMedia(virDomainObjPtr vm, virDomainDiskDefPtr disk)
 {
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(libxl_driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(libxl_driver);
     virDomainDiskDefPtr origdisk = NULL;
     libxl_device_disk x_disk;
     size_t i;
@@ -3026,14 +3000,13 @@ libxlDomainChangeEjectableMedia(virDomainObjPtr vm, virDomainDiskDefPtr disk)
     ret = 0;
 
  cleanup:
-    virObjectUnref(cfg);
     return ret;
 }
 
 static int
 libxlDomainAttachDeviceDiskLive(virDomainObjPtr vm, virDomainDeviceDefPtr dev)
 {
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(libxl_driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(libxl_driver);
     virDomainDiskDefPtr l_disk = dev->data.disk;
     libxl_device_disk x_disk;
     int ret = -1;
@@ -3097,7 +3070,6 @@ libxlDomainAttachDeviceDiskLive(virDomainObjPtr vm, virDomainDeviceDefPtr dev)
     }
 
  cleanup:
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -3106,7 +3078,7 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr driver,
                                virDomainObjPtr vm,
                                virDomainHostdevDefPtr hostdev)
 {
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     libxl_device_pci pcidev;
     virDomainHostdevDefPtr found;
     virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
@@ -3153,7 +3125,6 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr driver,
                                  vm->def->name, &hostdev, 1, NULL);
 
  cleanup:
-    virObjectUnref(cfg);
     libxl_device_pci_dispose(&pcidev);
     return ret;
 }
@@ -3164,7 +3135,7 @@ libxlDomainAttachControllerDevice(libxlDriverPrivatePtr driver,
                                   virDomainObjPtr vm,
                                   virDomainControllerDefPtr controller)
 {
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     const char *type = virDomainControllerTypeToString(controller->type);
     libxl_device_usbctrl usbctrl;
     int ret = -1;
@@ -3208,7 +3179,6 @@ libxlDomainAttachControllerDevice(libxlDriverPrivatePtr driver,
     ret = 0;
 
  cleanup:
-    virObjectUnref(cfg);
     libxl_device_usbctrl_dispose(&usbctrl);
     return ret;
 }
@@ -3218,7 +3188,7 @@ libxlDomainAttachHostUSBDevice(libxlDriverPrivatePtr driver,
                                virDomainObjPtr vm,
                                virDomainHostdevDefPtr hostdev)
 {
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     libxl_device_usbdev usbdev;
     virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
     int ret = -1;
@@ -3288,7 +3258,6 @@ libxlDomainAttachHostUSBDevice(libxlDriverPrivatePtr driver,
                                  vm->def->name, &hostdev, 1);
 
  cleanup:
-    virObjectUnref(cfg);
     libxl_device_usbdev_dispose(&usbdev);
     return ret;
 }
@@ -3332,7 +3301,7 @@ libxlDomainAttachHostDevice(libxlDriverPrivatePtr driver,
 static int
 libxlDomainDetachDeviceDiskLive(virDomainObjPtr vm, virDomainDeviceDefPtr dev)
 {
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(libxl_driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(libxl_driver);
     virDomainDiskDefPtr l_disk = NULL;
     libxl_device_disk x_disk;
     int idx;
@@ -3385,7 +3354,6 @@ libxlDomainDetachDeviceDiskLive(virDomainObjPtr vm, virDomainDeviceDefPtr dev)
     }
 
  cleanup:
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -3394,7 +3362,7 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver,
                            virDomainObjPtr vm,
                            virDomainNetDefPtr net)
 {
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainNetType actualType;
     libxl_device_nic nic;
     int ret = -1;
@@ -3475,7 +3443,6 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver,
             virDomainNetReleaseActualDevice(conn, vm->def, net);
     }
     virObjectUnref(conn);
-    virObjectUnref(cfg);
     virErrorRestore(&save_err);
     return ret;
 }
@@ -3643,7 +3610,7 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr driver,
                                virDomainObjPtr vm,
                                virDomainHostdevDefPtr hostdev)
 {
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainHostdevSubsysPtr subsys = &hostdev->source.subsys;
     virDomainHostdevSubsysPCIPtr pcisrc = &subsys->u.pci;
     libxl_device_pci pcidev;
@@ -3698,7 +3665,6 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr driver,
     virDomainHostdevDefFree(detach);
 
  cleanup:
-    virObjectUnref(cfg);
     libxl_device_pci_dispose(&pcidev);
     return ret;
 }
@@ -3714,7 +3680,7 @@ libxlDomainDetachControllerDevice(libxlDriverPrivatePtr driver,
     virDomainControllerDefPtr controller = dev->data.controller;
     const char *type = virDomainControllerTypeToString(controller->type);
     libxl_device_usbctrl usbctrl;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
 
     libxl_device_usbctrl_init(&usbctrl);
 
@@ -3750,7 +3716,6 @@ libxlDomainDetachControllerDevice(libxlDriverPrivatePtr driver,
 
  cleanup:
     virDomainControllerDefFree(detach);
-    virObjectUnref(cfg);
     libxl_device_usbctrl_dispose(&usbctrl);
     return ret;
 }
@@ -3760,7 +3725,7 @@ libxlDomainDetachHostUSBDevice(libxlDriverPrivatePtr driver,
                                virDomainObjPtr vm,
                                virDomainHostdevDefPtr hostdev)
 {
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainHostdevSubsysPtr subsys = &hostdev->source.subsys;
     virDomainHostdevSubsysUSBPtr usbsrc = &subsys->u.usb;
     virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
@@ -3818,7 +3783,6 @@ libxlDomainDetachHostUSBDevice(libxlDriverPrivatePtr driver,
 
  cleanup:
     virDomainHostdevDefFree(detach);
-    virObjectUnref(cfg);
     libxl_device_usbdev_dispose(&usbdev);
     return ret;
 }
@@ -3861,7 +3825,7 @@ libxlDomainDetachNetDevice(libxlDriverPrivatePtr driver,
                            virDomainObjPtr vm,
                            virDomainNetDefPtr net)
 {
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     int detachidx;
     virDomainNetDefPtr detach = NULL;
     libxl_device_nic nic;
@@ -3912,7 +3876,6 @@ libxlDomainDetachNetDevice(libxlDriverPrivatePtr driver,
         }
         virDomainNetRemove(vm->def, detachidx);
     }
-    virObjectUnref(cfg);
     virErrorRestore(&save_err);
     return ret;
 }
@@ -4101,7 +4064,7 @@ libxlDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
                              unsigned int flags)
 {
     libxlDriverPrivatePtr driver = dom->conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainObjPtr vm = NULL;
     virDomainDefPtr vmdef = NULL;
     virDomainDeviceDefPtr dev = NULL;
@@ -4173,7 +4136,6 @@ libxlDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
     virDomainDefFree(vmdef);
     virDomainDeviceDefFree(dev);
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -4189,7 +4151,7 @@ libxlDomainDetachDeviceFlags(virDomainPtr dom, const char *xml,
                              unsigned int flags)
 {
     libxlDriverPrivatePtr driver = dom->conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainObjPtr vm = NULL;
     virDomainDefPtr vmdef = NULL;
     virDomainDeviceDefPtr dev = NULL;
@@ -4263,7 +4225,6 @@ libxlDomainDetachDeviceFlags(virDomainPtr dom, const char *xml,
     virDomainDefFree(vmdef);
     virDomainDeviceDefFree(dev);
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -4279,7 +4240,7 @@ libxlDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml,
                              unsigned int flags)
 {
     libxlDriverPrivatePtr driver = dom->conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainObjPtr vm = NULL;
     virDomainDefPtr vmdef = NULL;
     virDomainDeviceDefPtr dev = NULL;
@@ -4345,7 +4306,6 @@ libxlDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml,
     virDomainDefFree(vmdef);
     virDomainDeviceDefFree(dev);
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -4354,7 +4314,7 @@ libxlNodeGetFreeMemory(virConnectPtr conn)
 {
     libxl_physinfo phy_info;
     libxlDriverPrivatePtr driver = conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     unsigned long long ret = 0;
 
     libxl_physinfo_init(&phy_info);
@@ -4371,7 +4331,6 @@ libxlNodeGetFreeMemory(virConnectPtr conn)
 
  cleanup:
     libxl_physinfo_dispose(&phy_info);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -4385,7 +4344,7 @@ libxlNodeGetCellsFreeMemory(virConnectPtr conn,
     int ret = -1, nr_nodes = 0;
     libxl_numainfo *numa_info = NULL;
     libxlDriverPrivatePtr driver = conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
 
     if (virNodeGetCellsFreeMemoryEnsureACL(conn) < 0)
         goto cleanup;
@@ -4419,7 +4378,6 @@ libxlNodeGetCellsFreeMemory(virConnectPtr conn,
 
  cleanup:
     libxl_numainfo_list_free(numa_info, nr_nodes);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -4484,7 +4442,7 @@ static int
 libxlDomainSetAutostart(virDomainPtr dom, int autostart)
 {
     libxlDriverPrivatePtr driver = dom->conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainObjPtr vm;
     char *configFile = NULL, *autostartLink = NULL;
     int ret = -1;
@@ -4548,7 +4506,6 @@ libxlDomainSetAutostart(virDomainPtr dom, int autostart)
     VIR_FREE(configFile);
     VIR_FREE(autostartLink);
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -4556,7 +4513,7 @@ static char *
 libxlDomainGetSchedulerType(virDomainPtr dom, int *nparams)
 {
     libxlDriverPrivatePtr driver = dom->conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainObjPtr vm;
     char * ret = NULL;
     const char *name = NULL;
@@ -4603,7 +4560,6 @@ libxlDomainGetSchedulerType(virDomainPtr dom, int *nparams)
 
  cleanup:
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -4614,7 +4570,7 @@ libxlDomainGetSchedulerParametersFlags(virDomainPtr dom,
                                        unsigned int flags)
 {
     libxlDriverPrivatePtr driver = dom->conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainObjPtr vm;
     libxl_domain_sched_params sc_info;
     libxl_scheduler sched_id;
@@ -4665,7 +4621,6 @@ libxlDomainGetSchedulerParametersFlags(virDomainPtr dom,
 
  cleanup:
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -4683,7 +4638,7 @@ libxlDomainSetSchedulerParametersFlags(virDomainPtr dom,
                                        unsigned int flags)
 {
     libxlDriverPrivatePtr driver = dom->conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainObjPtr vm;
     libxl_domain_sched_params sc_info;
     int sched_id;
@@ -4749,7 +4704,6 @@ libxlDomainSetSchedulerParametersFlags(virDomainPtr dom,
 
  cleanup:
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -4846,7 +4800,7 @@ libxlDomainGetNumaParameters(virDomainPtr dom,
                              unsigned int flags)
 {
     libxlDriverPrivatePtr driver = dom->conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainObjPtr vm;
     libxl_bitmap nodemap;
     virBitmapPtr nodes = NULL;
@@ -4954,7 +4908,6 @@ libxlDomainGetNumaParameters(virDomainPtr dom,
     virBitmapFree(nodes);
     libxl_bitmap_dispose(&nodemap);
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return ret;
 }
 #endif
@@ -5061,7 +5014,7 @@ libxlDomainGetTotalCPUStats(libxlDriverPrivatePtr driver,
                             virTypedParameterPtr params,
                             unsigned int nparams)
 {
-    libxlDriverConfigPtr cfg;
+    g_autoptr(libxlDriverConfig) cfg = NULL;
     libxl_dominfo d_info;
     int ret = -1;
 
@@ -5086,7 +5039,6 @@ libxlDomainGetTotalCPUStats(libxlDriverPrivatePtr driver,
 
  cleanup:
     libxl_dominfo_dispose(&d_info);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -5101,7 +5053,7 @@ libxlDomainGetPerCPUStats(libxlDriverPrivatePtr driver,
     libxl_vcpuinfo *vcpuinfo;
     int maxcpu, hostcpus;
     size_t i;
-    libxlDriverConfigPtr cfg;
+    g_autoptr(libxlDriverConfig) cfg = NULL;
     int ret = -1;
 
     if (nparams == 0 && ncpus != 0)
@@ -5130,7 +5082,6 @@ libxlDomainGetPerCPUStats(libxlDriverPrivatePtr driver,
  cleanup:
     if (vcpuinfo)
         libxl_vcpuinfo_list_free(vcpuinfo, maxcpu);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -5182,7 +5133,7 @@ libxlDomainMemoryStats(virDomainPtr dom,
                        unsigned int flags)
 {
     libxlDriverPrivatePtr driver = dom->conn->privateData;
-    libxlDriverConfigPtr cfg;
+    g_autoptr(libxlDriverConfig) cfg = NULL;
     virDomainObjPtr vm;
     libxl_dominfo d_info;
     unsigned mem, maxmem;
@@ -5226,7 +5177,6 @@ libxlDomainMemoryStats(virDomainPtr dom,
  cleanup:
     libxl_dominfo_dispose(&d_info);
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -6411,7 +6361,7 @@ libxlConnectGetDomainCapabilities(virConnectPtr conn,
                                   unsigned int flags)
 {
     libxlDriverPrivatePtr driver = conn->privateData;
-    libxlDriverConfigPtr cfg;
+    g_autoptr(libxlDriverConfig) cfg = NULL;
     char *ret = NULL;
     int virttype = VIR_DOMAIN_VIRT_XEN;
     virDomainCapsPtr domCaps = NULL;
@@ -6472,7 +6422,6 @@ libxlConnectGetDomainCapabilities(virConnectPtr conn,
 
  cleanup:
     virObjectUnref(domCaps);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -6483,7 +6432,7 @@ libxlConnectCompareCPU(virConnectPtr conn,
                        unsigned int flags)
 {
     libxlDriverPrivatePtr driver = conn->privateData;
-    libxlDriverConfigPtr cfg;
+    g_autoptr(libxlDriverConfig) cfg = NULL;
     int ret = VIR_CPU_COMPARE_ERROR;
     bool failIncompatible;
 
@@ -6500,7 +6449,6 @@ libxlConnectCompareCPU(virConnectPtr conn,
     ret = virCPUCompareXML(cfg->caps->host.arch, cfg->caps->host.cpu,
                            xmlDesc, failIncompatible);
 
-    virObjectUnref(cfg);
     return ret;
 }
 
diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c
index 11d3070935..50225855ae 100644
--- a/src/libxl/libxl_migration.c
+++ b/src/libxl/libxl_migration.c
@@ -348,7 +348,7 @@ libxlDoMigrateSrcSend(libxlDriverPrivatePtr driver,
                       unsigned long flags,
                       int sockfd)
 {
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     int xl_flags = 0;
     int ret;
 
@@ -363,7 +363,6 @@ libxlDoMigrateSrcSend(libxlDriverPrivatePtr driver,
         ret = -1;
     }
 
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -388,7 +387,7 @@ libxlDomainMigrationSrcBegin(virConnectPtr conn,
                              int *cookieoutlen)
 {
     libxlDriverPrivatePtr driver = conn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     libxlMigrationCookiePtr mig = NULL;
     virDomainDefPtr tmpdef = NULL;
     virDomainDefPtr def;
@@ -438,7 +437,6 @@ libxlDomainMigrationSrcBegin(virConnectPtr conn,
  cleanup:
     libxlMigrationCookieFree(mig);
     virDomainDefFree(tmpdef);
-    virObjectUnref(cfg);
     return xml;
 }
 
@@ -447,7 +445,7 @@ libxlDomainMigrationDstPrepareDef(libxlDriverPrivatePtr driver,
                                   const char *dom_xml,
                                   const char *dname)
 {
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     virDomainDefPtr def;
     char *name = NULL;
 
@@ -469,7 +467,6 @@ libxlDomainMigrationDstPrepareDef(libxlDriverPrivatePtr driver,
     }
 
  cleanup:
-    virObjectUnref(cfg);
     VIR_FREE(name);
     return def;
 }
@@ -657,7 +654,7 @@ libxlDomainMigrationDstPrepare(virConnectPtr dconn,
                                unsigned int flags)
 {
     libxlDriverPrivatePtr driver = dconn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     libxlMigrationCookiePtr mig = NULL;
     virDomainObjPtr vm = NULL;
     char *hostname = NULL;
@@ -828,7 +825,6 @@ libxlDomainMigrationDstPrepare(virConnectPtr dconn,
         virURIFree(uri);
     virObjectUnref(args);
     virDomainObjEndAPI(&vm);
-    virObjectUnref(cfg);
     return ret;
 }
 
@@ -1156,7 +1152,7 @@ libxlDomainMigrationSrcPerformP2P(libxlDriverPrivatePtr driver,
     bool useParams;
     virConnectPtr dconn = NULL;
     virErrorPtr orig_err = NULL;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
 
     virObjectUnlock(vm);
     dconn = virConnectOpenAuth(dconnuri, &virConnectAuthConfig, 0);
@@ -1199,7 +1195,6 @@ libxlDomainMigrationSrcPerformP2P(libxlDriverPrivatePtr driver,
     virErrorPreserveLast(&orig_err);
     virObjectUnlock(vm);
     virObjectUnref(dconn);
-    virObjectUnref(cfg);
     virObjectLock(vm);
     virErrorRestore(&orig_err);
     return ret;
@@ -1276,7 +1271,7 @@ libxlDomainMigrationDstFinish(virConnectPtr dconn,
                               int cancelled)
 {
     libxlDriverPrivatePtr driver = dconn->privateData;
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     libxlDomainObjPrivatePtr priv = vm->privateData;
     virObjectEventPtr event = NULL;
     virDomainPtr dom = NULL;
@@ -1366,7 +1361,6 @@ libxlDomainMigrationDstFinish(virConnectPtr dconn,
     /* EndJob for corresponding BeginJob in prepare phase */
     libxlDomainObjEndJob(driver, vm);
     virObjectEventStateQueue(driver->domainEventState, event);
-    virObjectUnref(cfg);
     return dom;
 }
 
@@ -1376,7 +1370,7 @@ libxlDomainMigrationSrcConfirm(libxlDriverPrivatePtr driver,
                                unsigned int flags,
                                int cancelled)
 {
-    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
     libxlDomainObjPrivatePtr priv = vm->privateData;
     virObjectEventPtr event = NULL;
     int ret = -1;
@@ -1422,6 +1416,5 @@ libxlDomainMigrationSrcConfirm(libxlDriverPrivatePtr driver,
     /* EndJob for corresponding BeginJob in begin phase */
     libxlDomainObjEndJob(driver, vm);
     virObjectEventStateQueue(driver->domainEventState, event);
-    virObjectUnref(cfg);
     return ret;
 }
diff --git a/tests/testutilsxen.c b/tests/testutilsxen.c
index d680fe36e3..62f01909f7 100644
--- a/tests/testutilsxen.c
+++ b/tests/testutilsxen.c
@@ -111,7 +111,7 @@ libxlDriverPrivatePtr testXLInitDriver(void)
 
 void testXLFreeDriver(libxlDriverPrivatePtr driver)
 {
-    virObjectUnref(driver->config);
+    g_clear_object(&driver->config);
     g_clear_object(&driver->xmlopt);
     virMutexDestroy(&driver->lock);
     g_free(driver);
-- 
2.25.3






[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux