[PATCH v2 29/40] datatypes: convert virDomain to GObject

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

 



Signed-off-by: Rafael Fonseca <r4f4rfs@xxxxxxxxx>
---
 src/conf/domain_event.c             |  58 ++++++------
 src/datatypes.c                     |  80 ++++++++++------
 src/datatypes.h                     |  20 ++--
 src/esx/esx_driver.c                |   7 +-
 src/hyperv/hyperv_driver.c          |   8 +-
 src/libvirt-domain.c                |   6 +-
 src/libvirt_private.syms            |   2 +-
 src/libxl/libxl_migration.c         |   3 +-
 src/locking/sanlock_helper.c        |   5 +-
 src/qemu/qemu_driver.c              |   6 +-
 src/qemu/qemu_migration.c           |   6 +-
 src/remote/remote_daemon_dispatch.c | 139 +++++++++-------------------
 src/remote/remote_driver.c          | 100 ++++++--------------
 src/rpc/gendispatch.pl              |   6 +-
 src/vbox/vbox_common.c              |  11 +--
 src/vz/vz_driver.c                  |   5 +-
 16 files changed, 183 insertions(+), 279 deletions(-)

diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index 33fbf10406..d1a4953686 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -1625,8 +1625,8 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
                                   virConnectObjectEventGenericCallback cb,
                                   void *cbopaque)
 {
-    virDomainPtr dom = virGetDomain(conn, event->meta.name,
-                                    event->meta.uuid, event->meta.id);
+    g_autoptr(virDomain) dom = virGetDomain(conn, event->meta.name,
+                                            event->meta.uuid, event->meta.id);
 
     if (!dom)
         return;
@@ -1641,13 +1641,13 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
                                                 lifecycleEvent->type,
                                                 lifecycleEvent->detail,
                                                 cbopaque);
-            goto cleanup;
+            return;
         }
 
     case VIR_DOMAIN_EVENT_ID_REBOOT:
         (cb)(conn, dom,
              cbopaque);
-        goto cleanup;
+        return;
 
     case VIR_DOMAIN_EVENT_ID_RTC_CHANGE:
         {
@@ -1657,7 +1657,7 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
             ((virConnectDomainEventRTCChangeCallback)cb)(conn, dom,
                                                          rtcChangeEvent->offset,
                                                          cbopaque);
-            goto cleanup;
+            return;
         }
 
     case VIR_DOMAIN_EVENT_ID_WATCHDOG:
@@ -1668,7 +1668,7 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
             ((virConnectDomainEventWatchdogCallback)cb)(conn, dom,
                                                         watchdogEvent->action,
                                                         cbopaque);
-            goto cleanup;
+            return;
         }
 
     case VIR_DOMAIN_EVENT_ID_IO_ERROR:
@@ -1681,7 +1681,7 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
                                                        ioErrorEvent->devAlias,
                                                        ioErrorEvent->action,
                                                        cbopaque);
-            goto cleanup;
+            return;
         }
 
     case VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON:
@@ -1695,7 +1695,7 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
                                                              ioErrorEvent->action,
                                                              ioErrorEvent->reason,
                                                              cbopaque);
-            goto cleanup;
+            return;
         }
 
     case VIR_DOMAIN_EVENT_ID_GRAPHICS:
@@ -1710,13 +1710,13 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
                                                         graphicsEvent->authScheme,
                                                         graphicsEvent->subject,
                                                         cbopaque);
-            goto cleanup;
+            return;
         }
 
     case VIR_DOMAIN_EVENT_ID_CONTROL_ERROR:
         (cb)(conn, dom,
              cbopaque);
-        goto cleanup;
+        return;
 
     case VIR_DOMAIN_EVENT_ID_BLOCK_JOB:
     case VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2:
@@ -1729,7 +1729,7 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
                                                         blockJobEvent->type,
                                                         blockJobEvent->status,
                                                         cbopaque);
-            goto cleanup;
+            return;
         }
 
     case VIR_DOMAIN_EVENT_ID_DISK_CHANGE:
@@ -1743,7 +1743,7 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
                                                           diskChangeEvent->devAlias,
                                                           diskChangeEvent->reason,
                                                           cbopaque);
-            goto cleanup;
+            return;
         }
 
     case VIR_DOMAIN_EVENT_ID_TRAY_CHANGE:
@@ -1755,7 +1755,7 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
                                                           trayChangeEvent->devAlias,
                                                           trayChangeEvent->reason,
                                                           cbopaque);
-            goto cleanup;
+            return;
         }
 
     case VIR_DOMAIN_EVENT_ID_PMWAKEUP:
@@ -1765,7 +1765,7 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
             ((virConnectDomainEventPMWakeupCallback)cb)(conn, dom,
                                                         pmEvent->reason,
                                                         cbopaque);
-            goto cleanup;
+            return;
         }
 
     case VIR_DOMAIN_EVENT_ID_PMSUSPEND:
@@ -1775,7 +1775,7 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
             ((virConnectDomainEventPMSuspendCallback)cb)(conn, dom,
                                                          pmEvent->reason,
                                                          cbopaque);
-            goto cleanup;
+            return;
         }
 
     case VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE:
@@ -1786,7 +1786,7 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
             ((virConnectDomainEventBalloonChangeCallback)cb)(conn, dom,
                                                              balloonChangeEvent->actual,
                                                              cbopaque);
-            goto cleanup;
+            return;
         }
 
     case VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK:
@@ -1796,7 +1796,7 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
             ((virConnectDomainEventPMSuspendDiskCallback)cb)(conn, dom,
                                                              pmEvent->reason,
                                                              cbopaque);
-            goto cleanup;
+            return;
         }
 
     case VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED:
@@ -1807,7 +1807,7 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
             ((virConnectDomainEventDeviceRemovedCallback)cb)(conn, dom,
                                                              deviceRemovedEvent->devAlias,
                                                              cbopaque);
-            goto cleanup;
+            return;
         }
 
     case VIR_DOMAIN_EVENT_ID_TUNABLE:
@@ -1818,7 +1818,7 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
                                                        tunableEvent->params,
                                                        tunableEvent->nparams,
                                                        cbopaque);
-            goto cleanup;
+            return;
         }
 
     case VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE:
@@ -1829,7 +1829,7 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
                                                               agentLifecycleEvent->state,
                                                               agentLifecycleEvent->reason,
                                                               cbopaque);
-            goto cleanup;
+            return;
         }
 
     case VIR_DOMAIN_EVENT_ID_DEVICE_ADDED:
@@ -1840,7 +1840,7 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
             ((virConnectDomainEventDeviceAddedCallback)cb)(conn, dom,
                                                            deviceAddedEvent->devAlias,
                                                            cbopaque);
-            goto cleanup;
+            return;
         }
 
     case VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION:
@@ -1851,7 +1851,7 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
             ((virConnectDomainEventMigrationIterationCallback)cb)(conn, dom,
                                                                   ev->iteration,
                                                                   cbopaque);
-            goto cleanup;
+            return;
         }
 
     case VIR_DOMAIN_EVENT_ID_JOB_COMPLETED:
@@ -1863,7 +1863,7 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
                                                              ev->params,
                                                              ev->nparams,
                                                              cbopaque);
-            goto cleanup;
+            return;
         }
 
     case VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED:
@@ -1874,7 +1874,7 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
             ((virConnectDomainEventDeviceRemovalFailedCallback)cb)(conn, dom,
                                                                    deviceRemovalFailedEvent->devAlias,
                                                                    cbopaque);
-            goto cleanup;
+            return;
         }
 
     case VIR_DOMAIN_EVENT_ID_METADATA_CHANGE:
@@ -1886,7 +1886,7 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
                                                               metadataChangeEvent->type,
                                                               metadataChangeEvent->nsuri,
                                                               cbopaque);
-            goto cleanup;
+            return;
         }
 
     case VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD:
@@ -1900,16 +1900,13 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
                                                               blockThresholdEvent->threshold,
                                                               blockThresholdEvent->excess,
                                                               cbopaque);
-            goto cleanup;
+            return;
         }
     case VIR_DOMAIN_EVENT_ID_LAST:
         break;
     }
 
     VIR_WARN("Unexpected event ID %d", event->eventID);
-
- cleanup:
-    virObjectUnref(dom);
 }
 
 
@@ -1963,7 +1960,7 @@ virDomainQemuMonitorEventDispatchFunc(virConnectPtr conn,
                                       virConnectObjectEventGenericCallback cb,
                                       void *cbopaque)
 {
-    virDomainPtr dom;
+    g_autoptr(virDomain) dom = NULL;
     virDomainQemuMonitorEventPtr qemuMonitorEvent;
     virDomainQemuMonitorEventData *data = cbopaque;
 
@@ -1978,7 +1975,6 @@ virDomainQemuMonitorEventDispatchFunc(virConnectPtr conn,
                                                    qemuMonitorEvent->micros,
                                                    qemuMonitorEvent->details,
                                                    data->opaque);
-    virObjectUnref(dom);
 }
 
 
diff --git a/src/datatypes.c b/src/datatypes.c
index 5d8752334d..e72e839562 100644
--- a/src/datatypes.c
+++ b/src/datatypes.c
@@ -35,11 +35,27 @@ VIR_LOG_INIT("datatypes");
 
 virClassPtr virConnectClass;
 virClassPtr virConnectCloseCallbackDataClass;
-virClassPtr virDomainClass;
 
 static void virConnectDispose(void *obj);
 static void virConnectCloseCallbackDataDispose(void *obj);
-static void virDomainDispose(void *obj);
+
+G_DEFINE_TYPE(virDomain, vir_domain, G_TYPE_OBJECT);
+static void virDomainDispose(GObject *obj);
+static void virDomainFinalize(GObject *obj);
+
+static void
+vir_domain_init(virDomain *dom G_GNUC_UNUSED)
+{
+}
+
+static void
+vir_domain_class_init(virDomainClass *klass)
+{
+    GObjectClass *obj = G_OBJECT_CLASS(klass);
+
+    obj->dispose = virDomainDispose;
+    obj->finalize = virDomainFinalize;
+}
 
 G_DEFINE_TYPE(virDomainCheckpoint, vir_domain_checkpoint, G_TYPE_OBJECT);
 static void virDomainCheckpointDispose(GObject *obj);
@@ -310,7 +326,6 @@ virDataTypesOnceInit(void)
 
     DECLARE_CLASS_LOCKABLE(virConnect);
     DECLARE_CLASS_LOCKABLE(virConnectCloseCallbackData);
-    DECLARE_CLASS(virDomain);
 
     DECLARE_CLASS_LOCKABLE(virAdmConnect);
     DECLARE_CLASS_LOCKABLE(virAdmConnectCloseCallbackData);
@@ -475,7 +490,7 @@ virConnectCloseCallbackDataGetCallback(virConnectCloseCallbackDataPtr closeData)
  * @id: domain ID
  *
  * Allocates a new domain object. When the object is no longer needed,
- * virObjectUnref() must be called in order to not leak data.
+ * g_object_unref() must be called in order to not leak data.
  *
  * Returns a pointer to the domain object, or NULL on error.
  */
@@ -485,17 +500,16 @@ virGetDomain(virConnectPtr conn,
              const unsigned char *uuid,
              int id)
 {
-    virDomainPtr ret = NULL;
+    g_autoptr(virDomain) ret = NULL;
 
     if (virDataTypesInitialize() < 0)
         return NULL;
 
-    virCheckConnectGoto(conn, error);
-    virCheckNonNullArgGoto(name, error);
-    virCheckNonNullArgGoto(uuid, error);
+    virCheckConnectReturn(conn, NULL);
+    virCheckNonNullArgReturn(name, NULL);
+    virCheckNonNullArgReturn(uuid, NULL);
 
-    if (!(ret = virObjectNew(virDomainClass)))
-        goto error;
+    ret = VIR_DOMAIN(g_object_new(VIR_TYPE_DOMAIN, NULL));
 
     ret->name = g_strdup(name);
 
@@ -503,34 +517,46 @@ virGetDomain(virConnectPtr conn,
     ret->id = id;
     memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
 
-    return ret;
-
- error:
-    virObjectUnref(ret);
-    return NULL;
+    return g_steal_pointer(&ret);
 }
 
 /**
  * virDomainDispose:
  * @obj: the domain to release
  *
- * Unconditionally release all memory associated with a domain.
- * The domain object must not be used once this method returns.
+ * Unreferences the associated connection object, which may also be
+ * released if its ref count hits zero.
+ */
+static void
+virDomainDispose(GObject *obj)
+{
+    virDomainPtr domain = VIR_DOMAIN(obj);
+
+    virObjectUnref(domain->conn);
+    domain->conn = NULL;
+
+    G_OBJECT_CLASS(vir_domain_parent_class)->dispose(obj);
+}
+
+/**
+ * virDomainFinalize:
+ * @obj: the domain to release
  *
- * It will also unreference the associated connection object,
- * which may also be released if its ref count hits zero.
+ * Unconditionally releases all memory associated with a domain.
+ * The domain object must not be used once this method returns.
  */
 static void
-virDomainDispose(void *obj)
+virDomainFinalize(GObject *obj)
 {
-    virDomainPtr domain = obj;
+    virDomainPtr domain = VIR_DOMAIN(obj);
     char uuidstr[VIR_UUID_STRING_BUFLEN];
 
     virUUIDFormat(domain->uuid, uuidstr);
     VIR_DEBUG("release domain %p %s %s", domain, domain->name, uuidstr);
 
     VIR_FREE(domain->name);
-    virObjectUnref(domain->conn);
+
+    G_OBJECT_CLASS(vir_domain_parent_class)->finalize(obj);
 }
 
 
@@ -1296,7 +1322,7 @@ virGetDomainCheckpoint(virDomainPtr domain,
     ret = VIR_DOMAIN_CHECKPOINT(g_object_new(VIR_TYPE_DOMAIN_CHECKPOINT, NULL));
     ret->name = g_strdup(name);
 
-    ret->domain = virObjectRef(domain);
+    ret->domain = g_object_ref(domain);
 
     return g_steal_pointer(&ret);
 }
@@ -1314,8 +1340,7 @@ virDomainCheckpointDispose(GObject *obj)
 {
     virDomainCheckpointPtr checkpoint = VIR_DOMAIN_CHECKPOINT(obj);
 
-    virObjectUnref(checkpoint->domain);
-    checkpoint->domain = NULL;
+    g_clear_object(&checkpoint->domain);
 
     G_OBJECT_CLASS(vir_domain_checkpoint_parent_class)->dispose(obj);
 }
@@ -1363,7 +1388,7 @@ virGetDomainSnapshot(virDomainPtr domain, const char *name)
     ret = VIR_DOMAIN_SNAPSHOT(g_object_new(VIR_TYPE_DOMAIN_SNAPSHOT, NULL));
     ret->name = g_strdup(name);
 
-    ret->domain = virObjectRef(domain);
+    ret->domain = g_object_ref(domain);
 
     return g_steal_pointer(&ret);
 }
@@ -1381,8 +1406,7 @@ virDomainSnapshotDispose(GObject *obj)
 {
     virDomainSnapshotPtr snapshot = VIR_DOMAIN_SNAPSHOT(obj);
 
-    virObjectUnref(snapshot->domain);
-    snapshot->domain = NULL;
+    g_clear_object(&snapshot->domain);
 
     G_OBJECT_CLASS(vir_domain_snapshot_parent_class)->dispose(obj);
 }
diff --git a/src/datatypes.h b/src/datatypes.h
index e96654cac1..f647096938 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -31,7 +31,9 @@
 #include <glib-object.h>
 
 extern virClassPtr virConnectClass;
-extern virClassPtr virDomainClass;
+
+#define VIR_TYPE_DOMAIN vir_domain_get_type()
+G_DECLARE_FINAL_TYPE(virDomain, vir_domain, VIR, DOMAIN, GObject);
 
 #define VIR_TYPE_DOMAIN_CHECKPOINT vir_domain_checkpoint_get_type()
 G_DECLARE_FINAL_TYPE(virDomainCheckpoint,
@@ -110,8 +112,8 @@ G_DECLARE_FINAL_TYPE(virAdmClient, vir_adm_client, VIR, ADM_CLIENT, GObject);
 
 #define virCheckDomainReturn(obj, retval) \
     do { \
-        virDomainPtr _dom = (obj); \
-        if (!virObjectIsClass(_dom, virDomainClass) || \
+        virDomainPtr _dom = VIR_DOMAIN(obj); \
+        if (_dom == NULL || \
             !virObjectIsClass(_dom->conn, virConnectClass)) { \
             virReportErrorHelper(VIR_FROM_DOM, VIR_ERR_INVALID_DOMAIN, \
                                  __FILE__, __FUNCTION__, __LINE__, \
@@ -122,8 +124,8 @@ G_DECLARE_FINAL_TYPE(virAdmClient, vir_adm_client, VIR, ADM_CLIENT, GObject);
     } while (0)
 #define virCheckDomainGoto(obj, label) \
     do { \
-        virDomainPtr _dom = (obj); \
-        if (!virObjectIsClass(_dom, virDomainClass) || \
+        virDomainPtr _dom = VIR_DOMAIN(obj); \
+        if (_dom == NULL || \
             !virObjectIsClass(_dom->conn, virConnectClass)) { \
             virReportErrorHelper(VIR_FROM_DOM, VIR_ERR_INVALID_DOMAIN, \
                                  __FILE__, __FUNCTION__, __LINE__, \
@@ -365,7 +367,7 @@ G_DECLARE_FINAL_TYPE(virAdmClient, vir_adm_client, VIR, ADM_CLIENT, GObject);
     do { \
         virDomainCheckpointPtr _check = VIR_DOMAIN_CHECKPOINT(obj); \
         if (_check == NULL || \
-            !virObjectIsClass(_check->domain, virDomainClass) || \
+            !VIR_IS_DOMAIN(_check->domain) || \
             !virObjectIsClass(_check->domain->conn, virConnectClass)) { \
             virReportErrorHelper(VIR_FROM_DOMAIN_CHECKPOINT, \
                                  VIR_ERR_INVALID_DOMAIN_CHECKPOINT, \
@@ -380,7 +382,7 @@ G_DECLARE_FINAL_TYPE(virAdmClient, vir_adm_client, VIR, ADM_CLIENT, GObject);
     do { \
         virDomainSnapshotPtr _snap = (obj); \
         if (_snap == NULL || \
-            !virObjectIsClass(_snap->domain, virDomainClass) || \
+            !VIR_IS_DOMAIN(_snap->domain) || \
             !virObjectIsClass(_snap->domain->conn, virConnectClass)) { \
             virReportErrorHelper(VIR_FROM_DOMAIN_SNAPSHOT, \
                                  VIR_ERR_INVALID_DOMAIN_SNAPSHOT, \
@@ -427,7 +429,7 @@ G_DECLARE_FINAL_TYPE(virAdmClient, vir_adm_client, VIR, ADM_CLIENT, GObject);
         char _uuidstr[VIR_UUID_STRING_BUFLEN]; \
         const char *_domname = NULL; \
  \
-        if (!virObjectIsClass(dom, virDomainClass)) { \
+        if (!VIR_IS_DOMAIN(dom)) { \
             memset(_uuidstr, 0, sizeof(_uuidstr)); \
         } else { \
             virUUIDFormat((dom)->uuid, _uuidstr); \
@@ -641,7 +643,7 @@ struct _virAdmClient {
 * Internal structure associated to a domain
 */
 struct _virDomain {
-    virObject parent;
+    GObject parent;
     virConnectPtr conn;                  /* pointer back to the connection */
     char *name;                          /* the domain external name */
     int id;                              /* the domain ID */
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 42f6ab9392..fc3a58c3de 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -5006,12 +5006,7 @@ esxConnectListAllDomains(virConnectPtr conn,
     ret = count;
 
  cleanup:
-    if (doms) {
-        for (id = 0; id < count; id++)
-            virObjectUnref(doms[id]);
-
-        VIR_FREE(doms);
-    }
+    virGObjectListFreeCount(doms, count);
 
     VIR_FREE(name);
     esxVI_AutoStartDefaults_Free(&autoStartDefaults);
diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index 4677a25ff8..a0eb14a947 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -1206,7 +1206,6 @@ hypervConnectListAllDomains(virConnectPtr conn,
     virDomainPtr *doms = NULL;
     int count = 0;
     int ret = -1;
-    size_t i;
 
     virCheckFlags(VIR_CONNECT_LIST_DOMAINS_FILTERS_ALL, -1);
 
@@ -1308,12 +1307,7 @@ hypervConnectListAllDomains(virConnectPtr conn,
     ret = count;
 
  cleanup:
-    if (doms) {
-        for (i = 0; i < count; ++i)
-            virObjectUnref(doms[i]);
-
-        VIR_FREE(doms);
-    }
+    virGObjectListFreeCount(doms, count);
 
     hypervFreeObject(priv, (hypervObject *)computerSystemList);
 
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index a12809c2d5..6f889f0c3b 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -565,7 +565,7 @@ virDomainFree(virDomainPtr domain)
 
     virCheckDomainReturn(domain, -1);
 
-    virObjectUnref(domain);
+    g_clear_object(&domain);
     return 0;
 }
 
@@ -590,13 +590,13 @@ virDomainFree(virDomainPtr domain)
 int
 virDomainRef(virDomainPtr domain)
 {
-    VIR_DOMAIN_DEBUG(domain, "refs=%d", domain ? domain->parent.u.s.refs : 0);
+    VIR_DOMAIN_DEBUG(domain);
 
     virResetLastError();
 
     virCheckDomainReturn(domain, -1);
 
-    virObjectRef(domain);
+    g_object_ref(domain);
     return 0;
 }
 
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 1514db8cb9..d96331e633 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1347,6 +1347,7 @@ virCPUx86FeatureFilterSelectMSR;
 
 # datatypes.h
 vir_domain_checkpoint_get_type;
+vir_domain_get_type;
 vir_domain_snapshot_get_type;
 vir_interface_get_type;
 vir_network_get_type;
@@ -1364,7 +1365,6 @@ virConnectCloseCallbackDataClass;
 virConnectCloseCallbackDataGetCallback;
 virConnectCloseCallbackDataRegister;
 virConnectCloseCallbackDataUnregister;
-virDomainClass;
 virGetConnect;
 virGetDomain;
 virGetDomainCheckpoint;
diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c
index 50804ca8b8..11d3070935 100644
--- a/src/libxl/libxl_migration.c
+++ b/src/libxl/libxl_migration.c
@@ -985,7 +985,7 @@ libxlDoMigrateSrcP2P(libxlDriverPrivatePtr driver,
                      const char *uri,
                      unsigned int flags)
 {
-    virDomainPtr ddomain = NULL;
+    g_autoptr(virDomain) ddomain = NULL;
     virTypedParameterPtr params = NULL;
     int nparams = 0;
     int maxparams = 0;
@@ -1113,7 +1113,6 @@ libxlDoMigrateSrcP2P(libxlDriverPrivatePtr driver,
     }
 
     if (ddomain) {
-        virObjectUnref(ddomain);
         ret = 0;
     } else {
         ret = -1;
diff --git a/src/locking/sanlock_helper.c b/src/locking/sanlock_helper.c
index 50deccfd67..7a8480932f 100644
--- a/src/locking/sanlock_helper.c
+++ b/src/locking/sanlock_helper.c
@@ -5,7 +5,7 @@
 #include "viralloc.h"
 #include "domain_conf.h"
 #include "virgettext.h"
-
+#include "datatypes.h"
 
 static int
 getArgs(int argc,
@@ -52,7 +52,7 @@ main(int argc, char **argv)
     virDomainLockFailureAction action;
     char *xml = NULL;
     virConnectPtr conn = NULL;
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     int ret = EXIT_FAILURE;
 
     int authTypes[] = {
@@ -99,7 +99,6 @@ main(int argc, char **argv)
     }
 
  cleanup:
-    virObjectUnref(dom);
     if (conn)
         virConnectClose(conn);
     VIR_FREE(xml);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b35cca4dcc..c05803f08a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1089,11 +1089,7 @@ qemuStateStop(void)
             ret = -1;
 
  cleanup:
-    if (domains) {
-        for (i = 0; i < numDomains; i++)
-            virObjectUnref(domains[i]);
-        VIR_FREE(domains);
-    }
+    virGObjectListFreeCount(domains, numDomains);
 
     return ret;
 }
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 13ff06f5c7..ab4ae8e150 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -3993,7 +3993,7 @@ qemuMigrationSrcPerformPeer2Peer2(virQEMUDriverPtr driver,
                                   unsigned long resource,
                                   qemuMigrationParamsPtr migParams)
 {
-    virDomainPtr ddomain = NULL;
+    g_autoptr(virDomain) ddomain = NULL;
     char *uri_out = NULL;
     char *cookie = NULL;
     char *dom_xml = NULL;
@@ -4103,7 +4103,6 @@ qemuMigrationSrcPerformPeer2Peer2(virQEMUDriverPtr driver,
 
  cleanup:
     if (ddomain) {
-        virObjectUnref(ddomain);
         ret = 0;
     } else {
         ret = -1;
@@ -4142,7 +4141,7 @@ qemuMigrationSrcPerformPeer2Peer3(virQEMUDriverPtr driver,
                                   bool useParams,
                                   unsigned long flags)
 {
-    virDomainPtr ddomain = NULL;
+    g_autoptr(virDomain) ddomain = NULL;
     char *uri_out = NULL;
     char *cookiein = NULL;
     char *cookieout = NULL;
@@ -4439,7 +4438,6 @@ qemuMigrationSrcPerformPeer2Peer3(virQEMUDriverPtr driver,
 
  cleanup:
     if (ddomain) {
-        virObjectUnref(ddomain);
         ret = 0;
     } else {
         ret = -1;
diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon_dispatch.c
index c5eca3bc0c..29944bdfa3 100644
--- a/src/remote/remote_daemon_dispatch.c
+++ b/src/remote/remote_daemon_dispatch.c
@@ -2264,7 +2264,7 @@ remoteDispatchDomainGetSchedulerType(virNetServerPtr server G_GNUC_UNUSED,
                                      remote_domain_get_scheduler_type_args *args,
                                      remote_domain_get_scheduler_type_ret *ret)
 {
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     char *type;
     int nparams;
     int rv = -1;
@@ -2286,7 +2286,6 @@ remoteDispatchDomainGetSchedulerType(virNetServerPtr server G_GNUC_UNUSED,
  cleanup:
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -2298,7 +2297,7 @@ remoteDispatchDomainGetSchedulerParameters(virNetServerPtr server G_GNUC_UNUSED,
                                            remote_domain_get_scheduler_parameters_args *args,
                                            remote_domain_get_scheduler_parameters_ret *ret)
 {
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     virTypedParameterPtr params = NULL;
     int nparams = 0;
     int rv = -1;
@@ -2334,7 +2333,6 @@ remoteDispatchDomainGetSchedulerParameters(virNetServerPtr server G_GNUC_UNUSED,
     if (rv < 0)
         virNetMessageSaveError(rerr);
     virTypedParamsFree(params, nparams);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -2346,7 +2344,7 @@ remoteDispatchDomainGetSchedulerParametersFlags(virNetServerPtr server G_GNUC_UN
                                                 remote_domain_get_scheduler_parameters_flags_args *args,
                                                 remote_domain_get_scheduler_parameters_flags_ret *ret)
 {
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     virTypedParameterPtr params = NULL;
     int nparams = 0;
     int rv = -1;
@@ -2383,7 +2381,6 @@ remoteDispatchDomainGetSchedulerParametersFlags(virNetServerPtr server G_GNUC_UN
     if (rv < 0)
         virNetMessageSaveError(rerr);
     virTypedParamsFree(params, nparams);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -2395,7 +2392,7 @@ remoteDispatchDomainMemoryStats(virNetServerPtr server G_GNUC_UNUSED,
                                 remote_domain_memory_stats_args *args,
                                 remote_domain_memory_stats_ret *ret)
 {
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     virDomainMemoryStatPtr stats = NULL;
     int nr_stats;
     size_t i;
@@ -2437,7 +2434,6 @@ remoteDispatchDomainMemoryStats(virNetServerPtr server G_GNUC_UNUSED,
  cleanup:
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virObjectUnref(dom);
     VIR_FREE(stats);
     return rv;
 }
@@ -2450,7 +2446,7 @@ remoteDispatchDomainBlockPeek(virNetServerPtr server G_GNUC_UNUSED,
                               remote_domain_block_peek_args *args,
                               remote_domain_block_peek_ret *ret)
 {
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     char *path;
     unsigned long long offset;
     size_t size;
@@ -2489,7 +2485,6 @@ remoteDispatchDomainBlockPeek(virNetServerPtr server G_GNUC_UNUSED,
         virNetMessageSaveError(rerr);
         VIR_FREE(ret->buffer.buffer_val);
     }
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -2502,7 +2497,7 @@ remoteDispatchDomainBlockStatsFlags(virNetServerPtr server G_GNUC_UNUSED,
                                     remote_domain_block_stats_flags_ret *ret)
 {
     virTypedParameterPtr params = NULL;
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     const char *path = args->path;
     int nparams = 0;
     unsigned int flags;
@@ -2550,7 +2545,6 @@ remoteDispatchDomainBlockStatsFlags(virNetServerPtr server G_GNUC_UNUSED,
     if (rv < 0)
         virNetMessageSaveError(rerr);
     virTypedParamsFree(params, nparams);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -2562,7 +2556,7 @@ remoteDispatchDomainMemoryPeek(virNetServerPtr server G_GNUC_UNUSED,
                                remote_domain_memory_peek_args *args,
                                remote_domain_memory_peek_ret *ret)
 {
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     unsigned long long offset;
     size_t size;
     unsigned int flags;
@@ -2599,7 +2593,6 @@ remoteDispatchDomainMemoryPeek(virNetServerPtr server G_GNUC_UNUSED,
         virNetMessageSaveError(rerr);
         VIR_FREE(ret->buffer.buffer_val);
     }
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -2611,7 +2604,7 @@ remoteDispatchDomainGetSecurityLabel(virNetServerPtr server G_GNUC_UNUSED,
                                      remote_domain_get_security_label_args *args,
                                      remote_domain_get_security_label_ret *ret)
 {
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     virSecurityLabelPtr seclabel = NULL;
     int rv = -1;
     virConnectPtr conn = remoteGetHypervisorConn(client);
@@ -2639,7 +2632,6 @@ remoteDispatchDomainGetSecurityLabel(virNetServerPtr server G_GNUC_UNUSED,
  cleanup:
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virObjectUnref(dom);
     VIR_FREE(seclabel);
     return rv;
 }
@@ -2652,7 +2644,7 @@ remoteDispatchDomainGetSecurityLabelList(virNetServerPtr server G_GNUC_UNUSED,
                                          remote_domain_get_security_label_list_args *args,
                                          remote_domain_get_security_label_list_ret *ret)
 {
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     virSecurityLabelPtr seclabels = NULL;
     int len, rv = -1;
     size_t i;
@@ -2689,7 +2681,6 @@ remoteDispatchDomainGetSecurityLabelList(virNetServerPtr server G_GNUC_UNUSED,
  cleanup:
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virObjectUnref(dom);
     VIR_FREE(seclabels);
     return rv;
 }
@@ -2738,7 +2729,7 @@ remoteDispatchDomainGetVcpuPinInfo(virNetServerPtr server G_GNUC_UNUSED,
                                    remote_domain_get_vcpu_pin_info_args *args,
                                    remote_domain_get_vcpu_pin_info_ret *ret)
 {
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     unsigned char *cpumaps = NULL;
     int num;
     int rv = -1;
@@ -2788,7 +2779,6 @@ remoteDispatchDomainGetVcpuPinInfo(virNetServerPtr server G_GNUC_UNUSED,
     if (rv < 0)
         virNetMessageSaveError(rerr);
     VIR_FREE(cpumaps);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -2800,7 +2790,7 @@ remoteDispatchDomainPinEmulator(virNetServerPtr server G_GNUC_UNUSED,
                                 remote_domain_pin_emulator_args *args)
 {
     int rv = -1;
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     virConnectPtr conn = remoteGetHypervisorConn(client);
 
     if (!conn)
@@ -2820,7 +2810,6 @@ remoteDispatchDomainPinEmulator(virNetServerPtr server G_GNUC_UNUSED,
  cleanup:
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -2833,7 +2822,7 @@ remoteDispatchDomainGetEmulatorPinInfo(virNetServerPtr server G_GNUC_UNUSED,
                                        remote_domain_get_emulator_pin_info_args *args,
                                        remote_domain_get_emulator_pin_info_ret *ret)
 {
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     unsigned char *cpumaps = NULL;
     int r;
     int rv = -1;
@@ -2867,7 +2856,6 @@ remoteDispatchDomainGetEmulatorPinInfo(virNetServerPtr server G_GNUC_UNUSED,
     if (rv < 0)
         virNetMessageSaveError(rerr);
     VIR_FREE(cpumaps);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -2879,7 +2867,7 @@ remoteDispatchDomainGetVcpus(virNetServerPtr server G_GNUC_UNUSED,
                              remote_domain_get_vcpus_args *args,
                              remote_domain_get_vcpus_ret *ret)
 {
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     virVcpuInfoPtr info = NULL;
     unsigned char *cpumaps = NULL;
     int info_len;
@@ -2945,7 +2933,6 @@ remoteDispatchDomainGetVcpus(virNetServerPtr server G_GNUC_UNUSED,
     }
     VIR_FREE(cpumaps);
     VIR_FREE(info);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -2960,7 +2947,7 @@ remoteDispatchDomainGetIOThreadInfo(virNetServerPtr server G_GNUC_UNUSED,
     int rv = -1;
     size_t i;
     virDomainIOThreadInfoPtr *info = NULL;
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     remote_domain_iothread_info *dst;
     int ninfo = 0;
     virConnectPtr conn = remoteGetHypervisorConn(client);
@@ -3010,7 +2997,6 @@ remoteDispatchDomainGetIOThreadInfo(virNetServerPtr server G_GNUC_UNUSED,
  cleanup:
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virObjectUnref(dom);
     if (ninfo >= 0)
         for (i = 0; i < ninfo; i++)
             virDomainIOThreadInfoFree(info[i]);
@@ -3128,7 +3114,7 @@ remoteDispatchDomainGetMemoryParameters(virNetServerPtr server G_GNUC_UNUSED,
                                         remote_domain_get_memory_parameters_args *args,
                                         remote_domain_get_memory_parameters_ret *ret)
 {
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     virTypedParameterPtr params = NULL;
     int nparams = 0;
     unsigned int flags;
@@ -3176,7 +3162,6 @@ remoteDispatchDomainGetMemoryParameters(virNetServerPtr server G_GNUC_UNUSED,
     if (rv < 0)
         virNetMessageSaveError(rerr);
     virTypedParamsFree(params, nparams);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -3188,7 +3173,7 @@ remoteDispatchDomainGetNumaParameters(virNetServerPtr server G_GNUC_UNUSED,
                                       remote_domain_get_numa_parameters_args *args,
                                       remote_domain_get_numa_parameters_ret *ret)
 {
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     virTypedParameterPtr params = NULL;
     int nparams = 0;
     unsigned int flags;
@@ -3236,7 +3221,6 @@ remoteDispatchDomainGetNumaParameters(virNetServerPtr server G_GNUC_UNUSED,
     if (rv < 0)
         virNetMessageSaveError(rerr);
     virTypedParamsFree(params, nparams);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -3248,7 +3232,7 @@ remoteDispatchDomainGetBlkioParameters(virNetServerPtr server G_GNUC_UNUSED,
                                        remote_domain_get_blkio_parameters_args *args,
                                        remote_domain_get_blkio_parameters_ret *ret)
 {
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     virTypedParameterPtr params = NULL;
     int nparams = 0;
     unsigned int flags;
@@ -3296,7 +3280,6 @@ remoteDispatchDomainGetBlkioParameters(virNetServerPtr server G_GNUC_UNUSED,
     if (rv < 0)
         virNetMessageSaveError(rerr);
     virTypedParamsFree(params, nparams);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -3444,7 +3427,7 @@ remoteDispatchDomainGetLaunchSecurityInfo(virNetServerPtr server G_GNUC_UNUSED,
                                           remote_domain_get_launch_security_info_args *args,
                                           remote_domain_get_launch_security_info_ret *ret)
 {
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     virTypedParameterPtr params = NULL;
     int nparams = 0;
     int rv = -1;
@@ -3472,7 +3455,6 @@ remoteDispatchDomainGetLaunchSecurityInfo(virNetServerPtr server G_GNUC_UNUSED,
     if (rv < 0)
         virNetMessageSaveError(rerr);
     virTypedParamsFree(params, nparams);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -3484,7 +3466,7 @@ remoteDispatchDomainGetPerfEvents(virNetServerPtr server G_GNUC_UNUSED,
                                   remote_domain_get_perf_events_args *args,
                                   remote_domain_get_perf_events_ret *ret)
 {
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     virTypedParameterPtr params = NULL;
     int nparams = 0;
     int rv = -1;
@@ -3512,7 +3494,6 @@ remoteDispatchDomainGetPerfEvents(virNetServerPtr server G_GNUC_UNUSED,
     if (rv < 0)
         virNetMessageSaveError(rerr);
     virTypedParamsFree(params, nparams);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -3524,7 +3505,7 @@ remoteDispatchDomainGetBlockJobInfo(virNetServerPtr server G_GNUC_UNUSED,
                                     remote_domain_get_block_job_info_args *args,
                                     remote_domain_get_block_job_info_ret *ret)
 {
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     virDomainBlockJobInfo tmp;
     int rv = -1;
     virConnectPtr conn = remoteGetHypervisorConn(client);
@@ -3549,7 +3530,6 @@ remoteDispatchDomainGetBlockJobInfo(virNetServerPtr server G_GNUC_UNUSED,
  cleanup:
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -3561,7 +3541,7 @@ remoteDispatchDomainGetBlockIoTune(virNetServerPtr server G_GNUC_UNUSED,
                                    remote_domain_get_block_io_tune_args *args,
                                    remote_domain_get_block_io_tune_ret *ret)
 {
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     int rv = -1;
     virTypedParameterPtr params = NULL;
     int nparams = 0;
@@ -3609,7 +3589,6 @@ remoteDispatchDomainGetBlockIoTune(virNetServerPtr server G_GNUC_UNUSED,
     if (rv < 0)
         virNetMessageSaveError(rerr);
     virTypedParamsFree(params, nparams);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -4416,7 +4395,7 @@ remoteDispatchDomainGetState(virNetServerPtr server G_GNUC_UNUSED,
                              remote_domain_get_state_args *args,
                              remote_domain_get_state_ret *ret)
 {
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     int rv = -1;
     virConnectPtr conn = remoteGetHypervisorConn(client);
 
@@ -4434,7 +4413,6 @@ remoteDispatchDomainGetState(virNetServerPtr server G_GNUC_UNUSED,
  cleanup:
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -4532,7 +4510,7 @@ remoteDispatchConnectDomainEventCallbackRegisterAny(virNetServerPtr server G_GNU
     daemonClientEventCallbackPtr ref;
     struct daemonClientPrivate *priv =
         virNetServerClientGetPrivateData(client);
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     virConnectPtr conn = remoteGetHypervisorConn(client);
 
     virMutexLock(&priv->lock);
@@ -4590,7 +4568,6 @@ remoteDispatchConnectDomainEventCallbackRegisterAny(virNetServerPtr server G_GNU
     remoteEventCallbackFree(callback);
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -4705,7 +4682,7 @@ qemuDispatchDomainMonitorCommand(virNetServerPtr server G_GNUC_UNUSED,
                                  qemu_domain_monitor_command_args *args,
                                  qemu_domain_monitor_command_ret *ret)
 {
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     int rv = -1;
     virConnectPtr conn = remoteGetHypervisorConn(client);
 
@@ -4724,7 +4701,6 @@ qemuDispatchDomainMonitorCommand(virNetServerPtr server G_GNUC_UNUSED,
  cleanup:
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -4738,7 +4714,7 @@ remoteDispatchDomainMigrateBegin3(virNetServerPtr server G_GNUC_UNUSED,
                                   remote_domain_migrate_begin3_ret *ret)
 {
     char *xml = NULL;
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     char *dname;
     char *xmlin;
     char *cookieout = NULL;
@@ -4772,7 +4748,6 @@ remoteDispatchDomainMigrateBegin3(virNetServerPtr server G_GNUC_UNUSED,
  cleanup:
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -4838,7 +4813,7 @@ remoteDispatchDomainMigratePerform3(virNetServerPtr server G_GNUC_UNUSED,
                                     remote_domain_migrate_perform3_args *args,
                                     remote_domain_migrate_perform3_ret *ret)
 {
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     char *xmlin;
     char *dname;
     char *uri;
@@ -4877,7 +4852,6 @@ remoteDispatchDomainMigratePerform3(virNetServerPtr server G_GNUC_UNUSED,
  cleanup:
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -4890,7 +4864,7 @@ remoteDispatchDomainMigrateFinish3(virNetServerPtr server G_GNUC_UNUSED,
                                    remote_domain_migrate_finish3_args *args,
                                    remote_domain_migrate_finish3_ret *ret)
 {
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     char *cookieout = NULL;
     int cookieoutlen = 0;
     char *uri;
@@ -4927,7 +4901,6 @@ remoteDispatchDomainMigrateFinish3(virNetServerPtr server G_GNUC_UNUSED,
         virNetMessageSaveError(rerr);
         VIR_FREE(cookieout);
     }
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -4939,7 +4912,7 @@ remoteDispatchDomainMigrateConfirm3(virNetServerPtr server G_GNUC_UNUSED,
                                     virNetMessageErrorPtr rerr,
                                     remote_domain_migrate_confirm3_args *args)
 {
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     int rv = -1;
     virConnectPtr conn = remoteGetHypervisorConn(client);
 
@@ -4960,7 +4933,6 @@ remoteDispatchDomainMigrateConfirm3(virNetServerPtr server G_GNUC_UNUSED,
  cleanup:
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -5035,7 +5007,7 @@ remoteDispatchDomainOpenGraphics(virNetServerPtr server G_GNUC_UNUSED,
                                  virNetMessageErrorPtr rerr,
                                  remote_domain_open_graphics_args *args)
 {
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     int rv = -1;
     int fd = -1;
     virConnectPtr conn = remoteGetHypervisorConn(client);
@@ -5061,7 +5033,6 @@ remoteDispatchDomainOpenGraphics(virNetServerPtr server G_GNUC_UNUSED,
     VIR_FORCE_CLOSE(fd);
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -5073,7 +5044,7 @@ remoteDispatchDomainOpenGraphicsFd(virNetServerPtr server G_GNUC_UNUSED,
                                    virNetMessageErrorPtr rerr,
                                    remote_domain_open_graphics_fd_args *args)
 {
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     int rv = -1;
     int fd = -1;
     virConnectPtr conn = remoteGetHypervisorConn(client);
@@ -5101,7 +5072,6 @@ remoteDispatchDomainOpenGraphicsFd(virNetServerPtr server G_GNUC_UNUSED,
     if (rv < 0)
         virNetMessageSaveError(rerr);
 
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -5114,7 +5084,7 @@ remoteDispatchDomainGetInterfaceParameters(virNetServerPtr server G_GNUC_UNUSED,
                                            remote_domain_get_interface_parameters_args *args,
                                            remote_domain_get_interface_parameters_ret *ret)
 {
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     virTypedParameterPtr params = NULL;
     const char *device = args->device;
     int nparams = 0;
@@ -5163,7 +5133,6 @@ remoteDispatchDomainGetInterfaceParameters(virNetServerPtr server G_GNUC_UNUSED,
     if (rv < 0)
         virNetMessageSaveError(rerr);
     virTypedParamsFree(params, nparams);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -5175,7 +5144,7 @@ remoteDispatchDomainGetCPUStats(virNetServerPtr server G_GNUC_UNUSED,
                                 remote_domain_get_cpu_stats_args *args,
                                 remote_domain_get_cpu_stats_ret *ret)
 {
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     virTypedParameterPtr params = NULL;
     int rv = -1;
     int percpu_len = 0;
@@ -5232,7 +5201,6 @@ remoteDispatchDomainGetCPUStats(virNetServerPtr server G_GNUC_UNUSED,
     if (rv < 0)
          virNetMessageSaveError(rerr);
     virTypedParamsFree(params, args->ncpus * args->nparams);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -5245,7 +5213,7 @@ remoteDispatchDomainGetDiskErrors(virNetServerPtr server G_GNUC_UNUSED,
                                   remote_domain_get_disk_errors_ret *ret)
 {
     int rv = -1;
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     virDomainDiskErrorPtr errors = NULL;
     int len = 0;
     virConnectPtr conn = remoteGetHypervisorConn(client);
@@ -5283,7 +5251,6 @@ remoteDispatchDomainGetDiskErrors(virNetServerPtr server G_GNUC_UNUSED,
  cleanup:
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virObjectUnref(dom);
     if (errors && len > 0) {
         size_t i;
         for (i = 0; i < len; i++)
@@ -5439,7 +5406,7 @@ lxcDispatchDomainOpenNamespace(virNetServerPtr server G_GNUC_UNUSED,
     int rv = -1;
     int *fdlist = NULL;
     int ret;
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     size_t i;
     virConnectPtr conn = remoteGetHypervisorConn(client);
 
@@ -5472,7 +5439,6 @@ lxcDispatchDomainOpenNamespace(virNetServerPtr server G_GNUC_UNUSED,
  cleanup:
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -5484,7 +5450,7 @@ remoteDispatchDomainGetJobStats(virNetServerPtr server G_GNUC_UNUSED,
                                 remote_domain_get_job_stats_args *args,
                                 remote_domain_get_job_stats_ret *ret)
 {
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     virTypedParameterPtr params = NULL;
     int nparams = 0;
     int rv = -1;
@@ -5513,7 +5479,6 @@ remoteDispatchDomainGetJobStats(virNetServerPtr server G_GNUC_UNUSED,
     if (rv < 0)
         virNetMessageSaveError(rerr);
     virTypedParamsFree(params, nparams);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -5526,7 +5491,7 @@ remoteDispatchDomainMigrateBegin3Params(virNetServerPtr server G_GNUC_UNUSED,
                                         remote_domain_migrate_begin3_params_ret *ret)
 {
     char *xml = NULL;
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     virTypedParameterPtr params = NULL;
     int nparams = 0;
     char *cookieout = NULL;
@@ -5567,7 +5532,6 @@ remoteDispatchDomainMigrateBegin3Params(virNetServerPtr server G_GNUC_UNUSED,
     virTypedParamsFree(params, nparams);
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -5705,7 +5669,7 @@ remoteDispatchDomainMigratePerform3Params(virNetServerPtr server G_GNUC_UNUSED,
 {
     virTypedParameterPtr params = NULL;
     int nparams = 0;
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     char *cookieout = NULL;
     int cookieoutlen = 0;
     char *dconnuri;
@@ -5748,7 +5712,6 @@ remoteDispatchDomainMigratePerform3Params(virNetServerPtr server G_GNUC_UNUSED,
     virTypedParamsFree(params, nparams);
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -5763,7 +5726,7 @@ remoteDispatchDomainMigrateFinish3Params(virNetServerPtr server G_GNUC_UNUSED,
 {
     virTypedParameterPtr params = NULL;
     int nparams = 0;
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     char *cookieout = NULL;
     int cookieoutlen = 0;
     int rv = -1;
@@ -5805,7 +5768,6 @@ remoteDispatchDomainMigrateFinish3Params(virNetServerPtr server G_GNUC_UNUSED,
         virNetMessageSaveError(rerr);
         VIR_FREE(cookieout);
     }
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -5819,7 +5781,7 @@ remoteDispatchDomainMigrateConfirm3Params(virNetServerPtr server G_GNUC_UNUSED,
 {
     virTypedParameterPtr params = NULL;
     int nparams = 0;
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     int rv = -1;
     virConnectPtr conn = remoteGetHypervisorConn(client);
 
@@ -5853,7 +5815,6 @@ remoteDispatchDomainMigrateConfirm3Params(virNetServerPtr server G_GNUC_UNUSED,
     virTypedParamsFree(params, nparams);
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -5916,7 +5877,7 @@ remoteDispatchDomainCreateXMLWithFiles(virNetServerPtr server G_GNUC_UNUSED,
                                        remote_domain_create_xml_with_files_ret *ret)
 {
     int rv = -1;
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     int *files = NULL;
     unsigned int nfiles = 0;
     size_t i;
@@ -5948,7 +5909,6 @@ remoteDispatchDomainCreateXMLWithFiles(virNetServerPtr server G_GNUC_UNUSED,
     VIR_FREE(files);
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -5961,7 +5921,7 @@ static int remoteDispatchDomainCreateWithFiles(virNetServerPtr server G_GNUC_UNU
                                                remote_domain_create_with_files_ret *ret)
 {
     int rv = -1;
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     int *files = NULL;
     unsigned int nfiles = 0;
     size_t i;
@@ -5996,7 +5956,6 @@ static int remoteDispatchDomainCreateWithFiles(virNetServerPtr server G_GNUC_UNU
     VIR_FREE(files);
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -6493,7 +6452,7 @@ qemuDispatchConnectDomainMonitorEventRegister(virNetServerPtr server G_GNUC_UNUS
     daemonClientEventCallbackPtr ref;
     struct daemonClientPrivate *priv =
         virNetServerClientGetPrivateData(client);
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     const char *event = args->event ? *args->event : NULL;
     virConnectPtr conn = remoteGetHypervisorConn(client);
 
@@ -6547,7 +6506,6 @@ qemuDispatchConnectDomainMonitorEventRegister(virNetServerPtr server G_GNUC_UNUS
     remoteEventCallbackFree(callback);
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -6606,7 +6564,7 @@ remoteDispatchDomainGetTime(virNetServerPtr server G_GNUC_UNUSED,
                             remote_domain_get_time_ret *ret)
 {
     int rv = -1;
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     long long seconds;
     unsigned int nseconds;
     virConnectPtr conn = remoteGetHypervisorConn(client);
@@ -6627,7 +6585,6 @@ remoteDispatchDomainGetTime(virNetServerPtr server G_GNUC_UNUSED,
  cleanup:
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virObjectUnref(dom);
     return rv;
 }
 
@@ -6939,7 +6896,7 @@ remoteDispatchDomainGetFSInfo(virNetServerPtr server G_GNUC_UNUSED,
     int rv = -1;
     size_t i, j;
     virDomainFSInfoPtr *info = NULL;
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     remote_domain_fsinfo *dst;
     int ninfo = 0;
     size_t ndisk;
@@ -7023,7 +6980,6 @@ remoteDispatchDomainGetFSInfo(virNetServerPtr server G_GNUC_UNUSED,
             VIR_FREE(ret->info.info_val);
         }
     }
-    virObjectUnref(dom);
     if (ninfo >= 0)
         for (i = 0; i < ninfo; i++)
             virDomainFSInfoFree(info[i]);
@@ -7123,7 +7079,7 @@ remoteDispatchDomainInterfaceAddresses(virNetServerPtr server G_GNUC_UNUSED,
 {
     size_t i;
     int rv = -1;
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     virDomainInterfacePtr *ifaces = NULL;
     int ifaces_count = 0;
     virConnectPtr conn = remoteGetHypervisorConn(client);
@@ -7146,8 +7102,6 @@ remoteDispatchDomainInterfaceAddresses(virNetServerPtr server G_GNUC_UNUSED,
     if (rv < 0)
         virNetMessageSaveError(rerr);
 
-    virObjectUnref(dom);
-
     if (ifaces && ifaces_count > 0) {
         for (i = 0; i < ifaces_count; i++)
             virDomainInterfaceFree(ifaces[i]);
@@ -7419,7 +7373,7 @@ remoteDispatchDomainGetGuestInfo(virNetServerPtr server G_GNUC_UNUSED,
 {
     int rv = -1;
     virConnectPtr conn = remoteGetHypervisorConn(client);
-    virDomainPtr dom = NULL;
+    g_autoptr(virDomain) dom = NULL;
     virTypedParameterPtr params = NULL;
     int nparams = 0;
 
@@ -7445,7 +7399,6 @@ remoteDispatchDomainGetGuestInfo(virNetServerPtr server G_GNUC_UNUSED,
     if (rv < 0)
         virNetMessageSaveError(rerr);
     virTypedParamsFree(params, nparams);
-    virObjectUnref(dom);
 
     return rv;
 }
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 58ae7528a8..f00083e0c3 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -4572,7 +4572,7 @@ remoteDomainBuildEventLifecycleHelper(virConnectPtr conn,
                                       int callbackID)
 {
     struct private_data *priv = conn->privateData;
-    virDomainPtr dom;
+    g_autoptr(virDomain) dom = NULL;
     virObjectEventPtr event = NULL;
 
     dom = get_nonnull_domain(conn, msg->dom);
@@ -4580,7 +4580,6 @@ remoteDomainBuildEventLifecycleHelper(virConnectPtr conn,
         return;
 
     event = virDomainEventLifecycleNewFromDom(dom, msg->event, msg->detail);
-    virObjectUnref(dom);
 
     virObjectEventStateQueueRemote(priv->eventState, event, callbackID);
 }
@@ -4610,7 +4609,7 @@ remoteDomainBuildEventRebootHelper(virConnectPtr conn,
                                    int callbackID)
 {
     struct private_data *priv = conn->privateData;
-    virDomainPtr dom;
+    g_autoptr(virDomain) dom = NULL;
     virObjectEventPtr event = NULL;
 
     dom = get_nonnull_domain(conn, msg->dom);
@@ -4618,7 +4617,6 @@ remoteDomainBuildEventRebootHelper(virConnectPtr conn,
         return;
 
     event = virDomainEventRebootNewFromDom(dom);
-    virObjectUnref(dom);
 
     virObjectEventStateQueueRemote(priv->eventState, event, callbackID);
 }
@@ -4647,7 +4645,7 @@ remoteDomainBuildEventRTCChangeHelper(virConnectPtr conn,
                                       int callbackID)
 {
     struct private_data *priv = conn->privateData;
-    virDomainPtr dom;
+    g_autoptr(virDomain) dom = NULL;
     virObjectEventPtr event = NULL;
 
     dom = get_nonnull_domain(conn, msg->dom);
@@ -4655,7 +4653,6 @@ remoteDomainBuildEventRTCChangeHelper(virConnectPtr conn,
         return;
 
     event = virDomainEventRTCChangeNewFromDom(dom, msg->offset);
-    virObjectUnref(dom);
 
     virObjectEventStateQueueRemote(priv->eventState, event, callbackID);
 }
@@ -4684,7 +4681,7 @@ remoteDomainBuildEventWatchdogHelper(virConnectPtr conn,
                                      int callbackID)
 {
     struct private_data *priv = conn->privateData;
-    virDomainPtr dom;
+    g_autoptr(virDomain) dom = NULL;
     virObjectEventPtr event = NULL;
 
     dom = get_nonnull_domain(conn, msg->dom);
@@ -4692,7 +4689,6 @@ remoteDomainBuildEventWatchdogHelper(virConnectPtr conn,
         return;
 
     event = virDomainEventWatchdogNewFromDom(dom, msg->action);
-    virObjectUnref(dom);
 
     virObjectEventStateQueueRemote(priv->eventState, event, callbackID);
 }
@@ -4721,7 +4717,7 @@ remoteDomainBuildEventIOErrorHelper(virConnectPtr conn,
                                     int callbackID)
 {
     struct private_data *priv = conn->privateData;
-    virDomainPtr dom;
+    g_autoptr(virDomain) dom = NULL;
     virObjectEventPtr event = NULL;
 
     dom = get_nonnull_domain(conn, msg->dom);
@@ -4732,7 +4728,6 @@ remoteDomainBuildEventIOErrorHelper(virConnectPtr conn,
                                             msg->srcPath,
                                             msg->devAlias,
                                             msg->action);
-    virObjectUnref(dom);
 
     virObjectEventStateQueueRemote(priv->eventState, event, callbackID);
 }
@@ -4761,7 +4756,7 @@ remoteDomainBuildEventIOErrorReasonHelper(virConnectPtr conn,
                                           int callbackID)
 {
     struct private_data *priv = conn->privateData;
-    virDomainPtr dom;
+    g_autoptr(virDomain) dom = NULL;
     virObjectEventPtr event = NULL;
 
     dom = get_nonnull_domain(conn, msg->dom);
@@ -4774,8 +4769,6 @@ remoteDomainBuildEventIOErrorReasonHelper(virConnectPtr conn,
                                                   msg->action,
                                                   msg->reason);
 
-    virObjectUnref(dom);
-
     virObjectEventStateQueueRemote(priv->eventState, event, callbackID);
 }
 static void
@@ -4803,7 +4796,7 @@ remoteDomainBuildEventBlockJobHelper(virConnectPtr conn,
                                      int callbackID)
 {
     struct private_data *priv = conn->privateData;
-    virDomainPtr dom;
+    g_autoptr(virDomain) dom = NULL;
     virObjectEventPtr event = NULL;
 
     dom = get_nonnull_domain(conn, msg->dom);
@@ -4813,8 +4806,6 @@ remoteDomainBuildEventBlockJobHelper(virConnectPtr conn,
     event = virDomainEventBlockJobNewFromDom(dom, msg->path, msg->type,
                                              msg->status);
 
-    virObjectUnref(dom);
-
     virObjectEventStateQueueRemote(priv->eventState, event, callbackID);
 }
 static void
@@ -4843,7 +4834,7 @@ remoteDomainBuildEventBlockJob2(virNetClientProgramPtr prog G_GNUC_UNUSED,
     virConnectPtr conn = opaque;
     remote_domain_event_block_job_2_msg *msg = evdata;
     struct private_data *priv = conn->privateData;
-    virDomainPtr dom;
+    g_autoptr(virDomain) dom = NULL;
     virObjectEventPtr event = NULL;
 
     dom = get_nonnull_domain(conn, msg->dom);
@@ -4853,8 +4844,6 @@ remoteDomainBuildEventBlockJob2(virNetClientProgramPtr prog G_GNUC_UNUSED,
     event = virDomainEventBlockJob2NewFromDom(dom, msg->dst, msg->type,
                                               msg->status);
 
-    virObjectUnref(dom);
-
     virObjectEventStateQueueRemote(priv->eventState, event, msg->callbackID);
 }
 
@@ -4864,7 +4853,7 @@ remoteDomainBuildEventGraphicsHelper(virConnectPtr conn,
                                      int callbackID)
 {
     struct private_data *priv = conn->privateData;
-    virDomainPtr dom;
+    g_autoptr(virDomain) dom = NULL;
     virObjectEventPtr event = NULL;
     virDomainEventGraphicsAddressPtr localAddr = NULL;
     virDomainEventGraphicsAddressPtr remoteAddr = NULL;
@@ -4904,8 +4893,6 @@ remoteDomainBuildEventGraphicsHelper(virConnectPtr conn,
                                              msg->authScheme,
                                              subject);
 
-    virObjectUnref(dom);
-
     virObjectEventStateQueueRemote(priv->eventState, event, callbackID);
     return;
 
@@ -4928,7 +4915,6 @@ remoteDomainBuildEventGraphicsHelper(virConnectPtr conn,
         VIR_FREE(subject->identities);
         VIR_FREE(subject);
     }
-    virObjectUnref(dom);
     return;
 }
 static void
@@ -4956,7 +4942,7 @@ remoteDomainBuildEventControlErrorHelper(virConnectPtr conn,
                                          int callbackID)
 {
     struct private_data *priv = conn->privateData;
-    virDomainPtr dom;
+    g_autoptr(virDomain) dom = NULL;
     virObjectEventPtr event = NULL;
 
     dom = get_nonnull_domain(conn, msg->dom);
@@ -4965,8 +4951,6 @@ remoteDomainBuildEventControlErrorHelper(virConnectPtr conn,
 
     event = virDomainEventControlErrorNewFromDom(dom);
 
-    virObjectUnref(dom);
-
     virObjectEventStateQueueRemote(priv->eventState, event, callbackID);
 }
 static void
@@ -4995,7 +4979,7 @@ remoteDomainBuildEventDiskChangeHelper(virConnectPtr conn,
                                        int callbackID)
 {
     struct private_data *priv = conn->privateData;
-    virDomainPtr dom;
+    g_autoptr(virDomain) dom = NULL;
     virObjectEventPtr event = NULL;
 
     dom = get_nonnull_domain(conn, msg->dom);
@@ -5008,8 +4992,6 @@ remoteDomainBuildEventDiskChangeHelper(virConnectPtr conn,
                                                msg->devAlias,
                                                msg->reason);
 
-    virObjectUnref(dom);
-
     virObjectEventStateQueueRemote(priv->eventState, event, callbackID);
 }
 static void
@@ -5038,7 +5020,7 @@ remoteDomainBuildEventTrayChangeHelper(virConnectPtr conn,
                                        int callbackID)
 {
     struct private_data *priv = conn->privateData;
-    virDomainPtr dom;
+    g_autoptr(virDomain) dom = NULL;
     virObjectEventPtr event = NULL;
 
     dom = get_nonnull_domain(conn, msg->dom);
@@ -5049,8 +5031,6 @@ remoteDomainBuildEventTrayChangeHelper(virConnectPtr conn,
                                                msg->devAlias,
                                                msg->reason);
 
-    virObjectUnref(dom);
-
     virObjectEventStateQueueRemote(priv->eventState, event, callbackID);
 }
 static void
@@ -5079,7 +5059,7 @@ remoteDomainBuildEventPMWakeupHelper(virConnectPtr conn,
                                      int reason)
 {
     struct private_data *priv = conn->privateData;
-    virDomainPtr dom;
+    g_autoptr(virDomain) dom = NULL;
     virObjectEventPtr event = NULL;
 
     dom = get_nonnull_domain(conn, msg->dom);
@@ -5088,8 +5068,6 @@ remoteDomainBuildEventPMWakeupHelper(virConnectPtr conn,
 
     event = virDomainEventPMWakeupNewFromDom(dom, reason);
 
-    virObjectUnref(dom);
-
     virObjectEventStateQueueRemote(priv->eventState, event, callbackID);
 }
 static void
@@ -5119,7 +5097,7 @@ remoteDomainBuildEventPMSuspendHelper(virConnectPtr conn,
                                       int reason)
 {
     struct private_data *priv = conn->privateData;
-    virDomainPtr dom;
+    g_autoptr(virDomain) dom = NULL;
     virObjectEventPtr event = NULL;
 
     dom = get_nonnull_domain(conn, msg->dom);
@@ -5128,8 +5106,6 @@ remoteDomainBuildEventPMSuspendHelper(virConnectPtr conn,
 
     event = virDomainEventPMSuspendNewFromDom(dom, reason);
 
-    virObjectUnref(dom);
-
     virObjectEventStateQueueRemote(priv->eventState, event, callbackID);
 }
 static void
@@ -5159,7 +5135,7 @@ remoteDomainBuildEventBalloonChangeHelper(virConnectPtr conn,
                                           int callbackID)
 {
     struct private_data *priv = conn->privateData;
-    virDomainPtr dom;
+    g_autoptr(virDomain) dom = NULL;
     virObjectEventPtr event = NULL;
 
     dom = get_nonnull_domain(conn, msg->dom);
@@ -5167,7 +5143,6 @@ remoteDomainBuildEventBalloonChangeHelper(virConnectPtr conn,
         return;
 
     event = virDomainEventBalloonChangeNewFromDom(dom, msg->actual);
-    virObjectUnref(dom);
 
     virObjectEventStateQueueRemote(priv->eventState, event, callbackID);
 }
@@ -5198,7 +5173,7 @@ remoteDomainBuildEventPMSuspendDiskHelper(virConnectPtr conn,
                                           int reason)
 {
     struct private_data *priv = conn->privateData;
-    virDomainPtr dom;
+    g_autoptr(virDomain) dom = NULL;
     virObjectEventPtr event = NULL;
 
     dom = get_nonnull_domain(conn, msg->dom);
@@ -5207,8 +5182,6 @@ remoteDomainBuildEventPMSuspendDiskHelper(virConnectPtr conn,
 
     event = virDomainEventPMSuspendDiskNewFromDom(dom, reason);
 
-    virObjectUnref(dom);
-
     virObjectEventStateQueueRemote(priv->eventState, event, callbackID);
 }
 static void
@@ -5238,7 +5211,7 @@ remoteDomainBuildEventDeviceRemovedHelper(virConnectPtr conn,
                                           int callbackID)
 {
     struct private_data *priv = conn->privateData;
-    virDomainPtr dom;
+    g_autoptr(virDomain) dom = NULL;
     virObjectEventPtr event = NULL;
 
     dom = get_nonnull_domain(conn, msg->dom);
@@ -5247,8 +5220,6 @@ remoteDomainBuildEventDeviceRemovedHelper(virConnectPtr conn,
 
     event = virDomainEventDeviceRemovedNewFromDom(dom, msg->devAlias);
 
-    virObjectUnref(dom);
-
     virObjectEventStateQueueRemote(priv->eventState, event, callbackID);
 }
 static void
@@ -5278,7 +5249,7 @@ remoteDomainBuildEventCallbackDeviceAdded(virNetClientProgramPtr prog G_GNUC_UNU
     virConnectPtr conn = opaque;
     remote_domain_event_callback_device_added_msg *msg = evdata;
     struct private_data *priv = conn->privateData;
-    virDomainPtr dom;
+    g_autoptr(virDomain) dom = NULL;
     virObjectEventPtr event = NULL;
 
     dom = get_nonnull_domain(conn, msg->dom);
@@ -5287,8 +5258,6 @@ remoteDomainBuildEventCallbackDeviceAdded(virNetClientProgramPtr prog G_GNUC_UNU
 
     event = virDomainEventDeviceAddedNewFromDom(dom, msg->devAlias);
 
-    virObjectUnref(dom);
-
     virObjectEventStateQueueRemote(priv->eventState, event, msg->callbackID);
 }
 
@@ -5301,7 +5270,7 @@ remoteDomainBuildEventCallbackDeviceRemovalFailed(virNetClientProgramPtr prog G_
     virConnectPtr conn = opaque;
     remote_domain_event_callback_device_removal_failed_msg *msg = evdata;
     struct private_data *priv = conn->privateData;
-    virDomainPtr dom;
+    g_autoptr(virDomain) dom = NULL;
     virObjectEventPtr event = NULL;
 
     if (!(dom = get_nonnull_domain(conn, msg->dom)))
@@ -5309,8 +5278,6 @@ remoteDomainBuildEventCallbackDeviceRemovalFailed(virNetClientProgramPtr prog G_
 
     event = virDomainEventDeviceRemovalFailedNewFromDom(dom, msg->devAlias);
 
-    virObjectUnref(dom);
-
     virObjectEventStateQueueRemote(priv->eventState, event, msg->callbackID);
 }
 
@@ -5322,7 +5289,7 @@ remoteDomainBuildEventCallbackTunable(virNetClientProgramPtr prog G_GNUC_UNUSED,
     virConnectPtr conn = opaque;
     remote_domain_event_callback_tunable_msg *msg = evdata;
     struct private_data *priv = conn->privateData;
-    virDomainPtr dom;
+    g_autoptr(virDomain) dom = NULL;
     virTypedParameterPtr params = NULL;
     int nparams = 0;
     virObjectEventPtr event = NULL;
@@ -5341,8 +5308,6 @@ remoteDomainBuildEventCallbackTunable(virNetClientProgramPtr prog G_GNUC_UNUSED,
 
     event = virDomainEventTunableNewFromDom(dom, params, nparams);
 
-    virObjectUnref(dom);
-
     virObjectEventStateQueueRemote(priv->eventState, event, msg->callbackID);
 }
 
@@ -5355,7 +5320,7 @@ remoteDomainBuildEventCallbackAgentLifecycle(virNetClientProgramPtr prog G_GNUC_
     virConnectPtr conn = opaque;
     remote_domain_event_callback_agent_lifecycle_msg *msg = evdata;
     struct private_data *priv = conn->privateData;
-    virDomainPtr dom;
+    g_autoptr(virDomain) dom = NULL;
     virObjectEventPtr event = NULL;
 
     if (!(dom = get_nonnull_domain(conn, msg->dom)))
@@ -5364,8 +5329,6 @@ remoteDomainBuildEventCallbackAgentLifecycle(virNetClientProgramPtr prog G_GNUC_
     event = virDomainEventAgentLifecycleNewFromDom(dom, msg->state,
                                                    msg->reason);
 
-    virObjectUnref(dom);
-
     virObjectEventStateQueueRemote(priv->eventState, event, msg->callbackID);
 }
 
@@ -5379,7 +5342,7 @@ remoteDomainBuildEventCallbackMigrationIteration(virNetClientProgramPtr prog G_G
     virConnectPtr conn = opaque;
     remote_domain_event_callback_migration_iteration_msg *msg = evdata;
     struct private_data *priv = conn->privateData;
-    virDomainPtr dom;
+    g_autoptr(virDomain) dom = NULL;
     virObjectEventPtr event = NULL;
 
     if (!(dom = get_nonnull_domain(conn, msg->dom)))
@@ -5387,8 +5350,6 @@ remoteDomainBuildEventCallbackMigrationIteration(virNetClientProgramPtr prog G_G
 
     event = virDomainEventMigrationIterationNewFromDom(dom, msg->iteration);
 
-    virObjectUnref(dom);
-
     virObjectEventStateQueueRemote(priv->eventState, event, msg->callbackID);
 }
 
@@ -5402,7 +5363,7 @@ remoteDomainBuildEventCallbackJobCompleted(virNetClientProgramPtr prog G_GNUC_UN
     virConnectPtr conn = opaque;
     remote_domain_event_callback_job_completed_msg *msg = evdata;
     struct private_data *priv = conn->privateData;
-    virDomainPtr dom;
+    g_autoptr(virDomain) dom = NULL;
     virObjectEventPtr event = NULL;
     virTypedParameterPtr params = NULL;
     int nparams = 0;
@@ -5420,8 +5381,6 @@ remoteDomainBuildEventCallbackJobCompleted(virNetClientProgramPtr prog G_GNUC_UN
 
     event = virDomainEventJobCompletedNewFromDom(dom, params, nparams);
 
-    virObjectUnref(dom);
-
     virObjectEventStateQueueRemote(priv->eventState, event, msg->callbackID);
 }
 
@@ -5434,7 +5393,7 @@ remoteDomainBuildEventCallbackMetadataChange(virNetClientProgramPtr prog G_GNUC_
     virConnectPtr conn = opaque;
     remote_domain_event_callback_metadata_change_msg *msg = evdata;
     struct private_data *priv = conn->privateData;
-    virDomainPtr dom;
+    g_autoptr(virDomain) dom = NULL;
     virObjectEventPtr event = NULL;
 
     if (!(dom = get_nonnull_domain(conn, msg->dom)))
@@ -5442,8 +5401,6 @@ remoteDomainBuildEventCallbackMetadataChange(virNetClientProgramPtr prog G_GNUC_
 
     event = virDomainEventMetadataChangeNewFromDom(dom, msg->type, msg->nsuri ? *msg->nsuri : NULL);
 
-    virObjectUnref(dom);
-
     virObjectEventStateQueueRemote(priv->eventState, event, msg->callbackID);
 }
 
@@ -5600,7 +5557,7 @@ remoteDomainBuildQemuMonitorEvent(virNetClientProgramPtr prog G_GNUC_UNUSED,
     virConnectPtr conn = opaque;
     struct private_data *priv = conn->privateData;
     qemu_domain_monitor_event_msg *msg = evdata;
-    virDomainPtr dom;
+    g_autoptr(virDomain) dom = NULL;
     virObjectEventPtr event = NULL;
 
     dom = get_nonnull_domain(conn, msg->dom);
@@ -5611,7 +5568,6 @@ remoteDomainBuildQemuMonitorEvent(virNetClientProgramPtr prog G_GNUC_UNUSED,
                                          msg->event, msg->seconds,
                                          msg->micros,
                                          msg->details ? *msg->details : NULL);
-    virObjectUnref(dom);
 
     virObjectEventStateQueueRemote(priv->eventState, event, msg->callbackID);
 }
@@ -5660,7 +5616,7 @@ remoteDomainBuildEventBlockThreshold(virNetClientProgramPtr prog G_GNUC_UNUSED,
     virConnectPtr conn = opaque;
     remote_domain_event_block_threshold_msg *msg = evdata;
     struct private_data *priv = conn->privateData;
-    virDomainPtr dom;
+    g_autoptr(virDomain) dom = NULL;
     virObjectEventPtr event = NULL;
 
     if (!(dom = get_nonnull_domain(conn, msg->dom)))
@@ -5670,8 +5626,6 @@ remoteDomainBuildEventBlockThreshold(virNetClientProgramPtr prog G_GNUC_UNUSED,
                                                    msg->path ? *msg->path : NULL,
                                                    msg->threshold, msg->excess);
 
-    virObjectUnref(dom);
-
     virObjectEventStateQueueRemote(priv->eventState, event, msg->callbackID);
 }
 
@@ -7779,7 +7733,7 @@ remoteConnectGetAllDomainStats(virConnectPtr conn,
 
  cleanup:
     if (elem) {
-        virObjectUnref(elem->dom);
+        g_clear_object(&elem->dom);
         VIR_FREE(elem);
     }
     virDomainStatsRecordListFree(tmpret);
diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl
index 29b3feb17c..8c45fa3bc7 100755
--- a/src/rpc/gendispatch.pl
+++ b/src/rpc/gendispatch.pl
@@ -196,6 +196,7 @@ sub get_conn_method {
 my %gobject_impl = (
     virAdmClient => 1,
     virAdmServer => 1,
+    virDomain => 1,
     virDomainCheckpoint => 1,
     virDomainSnapshot => 1,
     virInterface => 1,
@@ -626,7 +627,7 @@ elsif ($mode eq "server") {
                     my $type_name = name_to_TypeName($1);
                     my $unref_impl = get_unref_method("virDomain${type_name}");
 
-                    push(@vars_list, "virDomainPtr dom = NULL");
+                    push(@vars_list, "g_autoptr(virDomain) dom = NULL");
                     push(@vars_list, "virDomain${type_name}Ptr ${1} = NULL");
                     push(@getters_list,
                          "    if (!(dom = get_nonnull_domain($conn_var, args->${2}.dom)))\n" .
@@ -637,8 +638,7 @@ elsif ($mode eq "server") {
                     push(@args_list, "$1");
                     push(@free_list,
                          "    if ($1)\n" .
-                         "        $unref_impl($1);\n" .
-                         "    virObjectUnref(dom);");
+                         "        $unref_impl($1);\n");
                 } elsif ($args_member =~ m/^(?:(?:admin|remote)_string|remote_uuid) (\S+)<\S+>;/) {
                     push(@args_list, $conn_var) if !@args_list;
                     push(@args_list, "args->$1.$1_val");
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 7ca314d0dc..ef0bf8b5bd 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2287,7 +2287,7 @@ static virDomainPtr vboxDomainCreateXML(virConnectPtr conn, const char *xml,
      * change this behaviour to the expected one.
      */
 
-    virDomainPtr dom;
+    g_autoptr(virDomain) dom = NULL;
 
     virCheckFlags(0, NULL);
 
@@ -2297,11 +2297,10 @@ static virDomainPtr vboxDomainCreateXML(virConnectPtr conn, const char *xml,
 
     if (vboxDomainCreate(dom) < 0) {
         vboxDomainUndefineFlags(dom, 0);
-        virObjectUnref(dom);
         return NULL;
     }
 
-    return dom;
+    return g_steal_pointer(&dom);
 }
 
 static int vboxDomainIsActive(virDomainPtr dom)
@@ -7618,11 +7617,7 @@ vboxConnectListAllDomains(virConnectPtr conn,
     ret = count;
 
  cleanup:
-    if (doms) {
-        for (i = 0; i < count; i++)
-            virObjectUnref(doms[i]);
-    }
-    VIR_FREE(doms);
+    virGObjectListFreeCount(doms, count);
 
     gVBoxAPI.UArray.vboxArrayRelease(&machines);
     return ret;
diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index 4fe072233e..64383889a2 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -3146,7 +3146,7 @@ vzDomainMigratePerformP2P(virDomainObjPtr dom,
                           int nparams,
                           unsigned int flags)
 {
-    virDomainPtr ddomain = NULL;
+    g_autoptr(virDomain) ddomain = NULL;
     char *uri = NULL;
     char *cookiein = NULL;
     char *cookieout = NULL;
@@ -3222,7 +3222,6 @@ vzDomainMigratePerformP2P(virDomainObjPtr dom,
     virObjectLock(dom);
     if (ddomain)
         ret = 0;
-    virObjectUnref(ddomain);
 
     /* confirm step is NOOP thus no need to call it */
 
@@ -3735,7 +3734,7 @@ vzDomainGetAllStats(virConnectPtr conn,
 
  error:
     virTypedParamsFree(stat->params, stat->nparams);
-    virObjectUnref(stat->dom);
+    g_clear_object(&stat->dom);
     VIR_FREE(stat);
     return NULL;
 }
-- 
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