[PATCH v3 01/28] virSecurityManagerNewDriver: Fix code pattern

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

 



Use 'error' label to free allocated memory.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/security/security_manager.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/security/security_manager.c b/src/security/security_manager.c
index df7ffa84aa..e1b571ea52 100644
--- a/src/security/security_manager.c
+++ b/src/security/security_manager.c
@@ -73,8 +73,8 @@ virSecurityManagerNewDriver(virSecurityDriverPtr drv,
                             const char *virtDriver,
                             unsigned int flags)
 {
-    virSecurityManagerPtr mgr;
-    char *privateData;
+    virSecurityManagerPtr mgr = NULL;
+    char *privateData = NULL;
 
     if (virSecurityManagerInitialize() < 0)
         return NULL;
@@ -87,22 +87,22 @@ virSecurityManagerNewDriver(virSecurityDriverPtr drv,
     if (VIR_ALLOC_N(privateData, drv->privateDataLen) < 0)
         return NULL;
 
-    if (!(mgr = virObjectLockableNew(virSecurityManagerClass))) {
-        VIR_FREE(privateData);
-        return NULL;
-    }
+    if (!(mgr = virObjectLockableNew(virSecurityManagerClass)))
+        goto error;
 
     mgr->drv = drv;
     mgr->flags = flags;
     mgr->virtDriver = virtDriver;
-    mgr->privateData = privateData;
+    VIR_STEAL_PTR(mgr->privateData, privateData);
 
-    if (drv->open(mgr) < 0) {
-        virObjectUnref(mgr);
-        return NULL;
-    }
+    if (drv->open(mgr) < 0)
+        goto error;
 
     return mgr;
+ error:
+    VIR_FREE(privateData);
+    virObjectUnref(mgr);
+    return NULL;
 }
 
 
-- 
2.16.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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