]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
lib: Prefer g_autoptr(dnsmasqCaps) instead of explicit unref
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 11 Jan 2022 15:51:32 +0000 (16:51 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 18 Jan 2022 14:19:47 +0000 (15:19 +0100)
The dnsmasqCaps type has its own cleanup function defined and
ready to use via g_autoptr(). Use automatic cleanup instead of
an explicit one.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
src/util/virdnsmasq.c
tests/networkxml2conftest.c

index d304929d51826d777edb117942a943085677bff7..9f3da1d5e6bf50af74f573f23a7f116e6038955d 100644 (file)
@@ -702,44 +702,42 @@ dnsmasqCapsRefreshInternal(dnsmasqCaps *caps, bool force)
 static dnsmasqCaps *
 dnsmasqCapsNewEmpty(void)
 {
-    dnsmasqCaps *caps;
+    g_autoptr(dnsmasqCaps) caps = NULL;
 
     if (dnsmasqCapsInitialize() < 0)
         return NULL;
     if (!(caps = virObjectNew(dnsmasqCapsClass)))
         return NULL;
     caps->binaryPath = g_strdup(DNSMASQ);
-    return caps;
+    return g_steal_pointer(&caps);
 }
 
 dnsmasqCaps *
 dnsmasqCapsNewFromBuffer(const char *buf)
 {
-    dnsmasqCaps *caps = dnsmasqCapsNewEmpty();
+    g_autoptr(dnsmasqCaps) caps = dnsmasqCapsNewEmpty();
 
     if (!caps)
         return NULL;
 
-    if (dnsmasqCapsSetFromBuffer(caps, buf) < 0) {
-        virObjectUnref(caps);
+    if (dnsmasqCapsSetFromBuffer(caps, buf) < 0)
         return NULL;
-    }
-    return caps;
+
+    return g_steal_pointer(&caps);
 }
 
 dnsmasqCaps *
 dnsmasqCapsNewFromBinary(void)
 {
-    dnsmasqCaps *caps = dnsmasqCapsNewEmpty();
+    g_autoptr(dnsmasqCaps) caps = dnsmasqCapsNewEmpty();
 
     if (!caps)
         return NULL;
 
-    if (dnsmasqCapsRefreshInternal(caps, true) < 0) {
-        virObjectUnref(caps);
+    if (dnsmasqCapsRefreshInternal(caps, true) < 0)
         return NULL;
-    }
-    return caps;
+
+    return g_steal_pointer(&caps);
 }
 
 const char *
index 178c74d9af3ce82b6c5e8162235ddadc25636c15..d79c2b47833948eec26adb40fc42eed437ab4e22 100644 (file)
@@ -112,8 +112,9 @@ static int
 mymain(void)
 {
     int ret = 0;
-    dnsmasqCaps *full
-        = dnsmasqCapsNewFromBuffer("Dnsmasq version 2.67\n--bind-dynamic\n--ra-param");
+    g_autoptr(dnsmasqCaps) full = NULL;
+
+    full = dnsmasqCapsNewFromBuffer("Dnsmasq version 2.67\n--bind-dynamic\n--ra-param");
 
 #define DO_TEST(xname, xcaps) \
     do { \
@@ -154,8 +155,6 @@ mymain(void)
     DO_TEST("leasetime-hours", full);
     DO_TEST("leasetime-infinite", full);
 
-    virObjectUnref(full);
-
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }