[libvirt PATCH 3/8] Use g_auto for stealing virCaps

Ján Tomko jtomko at redhat.com
Fri Dec 10 16:06:13 UTC 2021


Convert all the functions that generate virCaps to use g_auto
and g_steal_pointer.

Signed-off-by: Ján Tomko <jtomko at redhat.com>
---
 src/ch/ch_conf.c               | 5 ++---
 src/hyperv/hyperv_driver.c     | 5 ++---
 src/libxl/libxl_capabilities.c | 5 ++---
 src/lxc/lxc_conf.c             | 5 ++---
 src/test/test_driver.c         | 5 ++---
 src/vmware/vmware_conf.c       | 5 ++---
 src/vz/vz_driver.c             | 5 ++---
 tests/qemucaps2xmltest.c       | 5 ++---
 tests/testutilsxen.c           | 5 ++---
 9 files changed, 18 insertions(+), 27 deletions(-)

diff --git a/src/ch/ch_conf.c b/src/ch/ch_conf.c
index ef6f4b5ba8..a9cbbca560 100644
--- a/src/ch/ch_conf.c
+++ b/src/ch/ch_conf.c
@@ -52,7 +52,7 @@ VIR_ONCE_GLOBAL_INIT(virCHConfig);
 /* Functions */
 virCaps *virCHDriverCapsInit(void)
 {
-    virCaps *caps;
+    g_autoptr(virCaps) caps = NULL;
     virCapsGuest *guest;
 
     if ((caps = virCapabilitiesNew(virArchFromHost(),
@@ -70,10 +70,9 @@ virCaps *virCHDriverCapsInit(void)
 
     virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_KVM,
                                   NULL, NULL, 0, NULL);
-    return caps;
+    return g_steal_pointer(&caps);
 
  cleanup:
-    virObjectUnref(caps);
     return NULL;
 }
 
diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index bafec27a88..4d938f4d7f 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -262,7 +262,7 @@ hypervLookupHostSystemBiosUuid(hypervPrivate *priv, unsigned char *uuid)
 static virCaps *
 hypervCapsInit(hypervPrivate *priv)
 {
-    virCaps *caps = NULL;
+    g_autoptr(virCaps) caps = NULL;
     virCapsGuest *guest = NULL;
 
     caps = virCapabilitiesNew(VIR_ARCH_X86_64, 1, 1);
@@ -287,10 +287,9 @@ hypervCapsInit(hypervPrivate *priv)
     virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_HYPERV,
                                   NULL, NULL, 0, NULL);
 
-    return caps;
+    return g_steal_pointer(&caps);
 
  error:
-    virObjectUnref(caps);
     return NULL;
 }
 
diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c
index 6263b5c8b5..9084dacb40 100644
--- a/src/libxl/libxl_capabilities.c
+++ b/src/libxl/libxl_capabilities.c
@@ -635,7 +635,7 @@ libxlMakeDomainDeviceHostdevCaps(virDomainCapsDeviceHostdev *dev)
 virCaps *
 libxlMakeCapabilities(libxl_ctx *ctx)
 {
-    virCaps *caps;
+    g_autoptr(virCaps) caps = NULL;
 
 #ifdef LIBXL_HAVE_NO_SUSPEND_RESUME
     if ((caps = virCapabilitiesNew(virArchFromHost(), false, false)) == NULL)
@@ -653,10 +653,9 @@ libxlMakeCapabilities(libxl_ctx *ctx)
     if (libxlCapsInitGuests(ctx, caps) < 0)
         goto error;
 
-    return caps;
+    return g_steal_pointer(&caps);
 
  error:
-    virObjectUnref(caps);
     return NULL;
 }
 
diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c
index 73156f15a3..e9186b879e 100644
--- a/src/lxc/lxc_conf.c
+++ b/src/lxc/lxc_conf.c
@@ -58,7 +58,7 @@ VIR_ONCE_GLOBAL_INIT(virLXCConfig);
 /* Functions */
 virCaps *virLXCDriverCapsInit(virLXCDriver *driver)
 {
-    virCaps *caps;
+    g_autoptr(virCaps) caps = NULL;
     virCapsGuest *guest;
     virArch altArch;
     g_autofree char *lxc_path = NULL;
@@ -138,10 +138,9 @@ virCaps *virLXCDriverCapsInit(virLXCDriver *driver)
         VIR_INFO("No driver, not initializing security driver");
     }
 
-    return caps;
+    return g_steal_pointer(&caps);
 
  error:
-    virObjectUnref(caps);
     return NULL;
 }
 
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 995e63b004..020a9e5df0 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -291,7 +291,7 @@ static virCaps *
 testBuildCapabilities(virConnectPtr conn)
 {
     testDriver *privconn = conn->privateData;
-    virCaps *caps;
+    g_autoptr(virCaps) caps = NULL;
     virCapsGuest *guest;
     int guest_types[] = { VIR_DOMAIN_OSTYPE_HVM,
                           VIR_DOMAIN_OSTYPE_XEN };
@@ -361,10 +361,9 @@ testBuildCapabilities(virConnectPtr conn)
 
     caps->host.secModels[0].doi = g_strdup("");
 
-    return caps;
+    return g_steal_pointer(&caps);
 
  error:
-    virObjectUnref(caps);
     return NULL;
 }
 
diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c
index 8c8ecc8120..3f6b51ac44 100644
--- a/src/vmware/vmware_conf.c
+++ b/src/vmware/vmware_conf.c
@@ -64,7 +64,7 @@ vmwareFreeDriver(struct vmware_driver *driver)
 virCaps *
 vmwareCapsInit(void)
 {
-    virCaps *caps = NULL;
+    g_autoptr(virCaps) caps = NULL;
     virCapsGuest *guest = NULL;
 
     if ((caps = virCapabilitiesNew(virArchFromHost(),
@@ -106,11 +106,10 @@ vmwareCapsInit(void)
         guest = NULL;
     }
 
-    return caps;
+    return g_steal_pointer(&caps);
 
  error:
     virCapabilitiesFreeGuest(guest);
-    virObjectUnref(caps);
     return NULL;
 }
 
diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index 83ff119dd9..1353efa6ab 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -94,7 +94,7 @@ vzCapsAddGuestDomain(virCaps *caps,
 static virCaps *
 vzBuildCapabilities(void)
 {
-    virCaps *caps = NULL;
+    g_autoptr(virCaps) caps = NULL;
     virNodeInfo nodeinfo;
     virDomainOSType ostypes[] = {
         VIR_DOMAIN_OSTYPE_HVM,
@@ -137,10 +137,9 @@ vzBuildCapabilities(void)
     if (virCapabilitiesAddHostMigrateTransport(caps, "vzmigr") < 0)
         goto error;
 
-    return caps;
+    return g_steal_pointer(&caps);
 
  error:
-    virObjectUnref(caps);
     return NULL;
 }
 
diff --git a/tests/qemucaps2xmltest.c b/tests/qemucaps2xmltest.c
index 78a2148e1a..aec4647678 100644
--- a/tests/qemucaps2xmltest.c
+++ b/tests/qemucaps2xmltest.c
@@ -86,7 +86,7 @@ static virCaps *
 testGetCaps(char *capsData, const testQemuData *data)
 {
     g_autoptr(virQEMUCaps) qemuCaps = NULL;
-    virCaps *caps = NULL;
+    g_autoptr(virCaps) caps = NULL;
     virArch arch = virArchFromString(data->archName);
     g_autofree char *binary = NULL;
 
@@ -110,10 +110,9 @@ testGetCaps(char *capsData, const testQemuData *data)
         goto error;
     }
 
-    return caps;
+    return g_steal_pointer(&caps);
 
  error:
-    virObjectUnref(caps);
     return NULL;
 }
 
diff --git a/tests/testutilsxen.c b/tests/testutilsxen.c
index 1b584e34b1..821ee49d94 100644
--- a/tests/testutilsxen.c
+++ b/tests/testutilsxen.c
@@ -11,7 +11,7 @@
 static virCaps *
 testXLInitCaps(void)
 {
-    virCaps *caps;
+    g_autoptr(virCaps) caps = NULL;
     virCapsGuest *guest;
     virCapsGuestMachine **machines;
     int nmachines;
@@ -68,11 +68,10 @@ testXLInitCaps(void)
 
     virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_XEN,
                                   NULL, NULL, 0, NULL);
-    return caps;
+    return g_steal_pointer(&caps);
 
  cleanup:
     virCapabilitiesFreeMachines(machines, nmachines);
-    virObjectUnref(caps);
     return NULL;
 }
 
-- 
2.31.1




More information about the libvir-list mailing list