Use an error label to converge all the clean up processing options.

Signed-off-by: John Ferlan <jfer...@redhat.com>
---
 src/conf/virstorageobj.c | 37 +++++++++++++++++++------------------
 1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c
index 799b8c9fa..471262f29 100644
--- a/src/conf/virstorageobj.c
+++ b/src/conf/virstorageobj.c
@@ -1115,8 +1115,8 @@ virStoragePoolObjLoad(virStoragePoolObjListPtr pools,
                       const char *path,
                       const char *autostartLink)
 {
-    virStoragePoolDefPtr def;
-    virStoragePoolObjPtr obj;
+    virStoragePoolDefPtr def = NULL;
+    virStoragePoolObjPtr obj = NULL;
 
     if (!(def = virStoragePoolDefParseFile(path)))
         return NULL;
@@ -1126,32 +1126,33 @@ virStoragePoolObjLoad(virStoragePoolObjListPtr pools,
                        _("Storage pool config filename '%s' does "
                          "not match pool name '%s'"),
                        path, def->name);
-        virStoragePoolDefFree(def);
-        return NULL;
+        goto error;
     }
 
-    if (!(obj = virStoragePoolObjAssignDef(pools, def))) {
-        virStoragePoolDefFree(def);
-        return NULL;
-    }
+    if (!(obj = virStoragePoolObjAssignDef(pools, def)))
+        goto error;
+    def = NULL;
 
     VIR_FREE(obj->configFile);  /* for driver reload */
-    if (VIR_STRDUP(obj->configFile, path) < 0) {
-        virStoragePoolObjRemove(pools, obj);
-        virObjectUnref(obj);
-        return NULL;
-    }
+    if (VIR_STRDUP(obj->configFile, path) < 0)
+        goto error;
+
     VIR_FREE(obj->autostartLink); /* for driver reload */
-    if (VIR_STRDUP(obj->autostartLink, autostartLink) < 0) {
-        virStoragePoolObjRemove(pools, obj);
-        virObjectUnref(obj);
-        return NULL;
-    }
+    if (VIR_STRDUP(obj->autostartLink, autostartLink) < 0)
+        goto error;
 
     obj->autostart = virFileLinkPointsTo(obj->autostartLink,
                                          obj->configFile);
 
     return obj;
+
+ error:
+    if (obj) {
+        virStoragePoolObjRemove(pools, obj);
+        virObjectUnref(obj);
+    }
+    virStoragePoolDefFree(def);
+    return NULL;
 }
 
 
-- 
2.13.6

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

Reply via email to