[PATCH 7/7] qemuDomainObjPrivateAlloc: Fix unlikely memory leak

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

 



Additional cleanup paths add the possibility of not freeing earlier
stuff. Add an AUTOPTR handler for qemuDomainObjPrivate and use it in
qemuDomainObjPrivateAlloc

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_domain.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 8d1ecc0140..7e2efc8168 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1891,22 +1891,22 @@ qemuDomainObjPrivateFree(void *data)
     g_free(priv);
 }

+G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuDomainObjPrivate, qemuDomainObjPrivateFree);
+

 static void *
 qemuDomainObjPrivateAlloc(void *opaque)
 {
-    qemuDomainObjPrivate *priv;
-
-    priv = g_new0(qemuDomainObjPrivate, 1);
+    g_autoptr(qemuDomainObjPrivate) priv = g_new0(qemuDomainObjPrivate, 1);

     if (qemuDomainObjInitJob(&priv->job, &qemuPrivateJobCallbacks) < 0) {
         virReportSystemError(errno, "%s",
                              _("Unable to init qemu driver mutexes"));
-        goto error;
+        return NULL;
     }

     if (!(priv->devs = virChrdevAlloc()))
-        goto error;
+        return NULL;

     priv->blockjobs = virHashNew(virObjectFreeHashData);

@@ -1915,11 +1915,7 @@ qemuDomainObjPrivateAlloc(void *opaque)
     priv->migMaxBandwidth = QEMU_DOMAIN_MIG_BANDWIDTH_MAX;
     priv->driver = opaque;

-    return priv;
-
- error:
-    VIR_FREE(priv);
-    return NULL;
+    return g_steal_pointer(&priv);
 }


-- 
2.31.1




[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