[PATCH v2 02/32] util: Rework virStorageAuthDefCopy

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

 



Rather than having an error path, let's rework the code to allocate
and fill into an @authdef variable and then steal that into @ret when
we are successful leaving just a cleanup: path.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
Reviewed-by: Erik Skultety <eskultet@xxxxxxxxxx>
---
 src/util/virstoragefile.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 98f9bc803f..7fbeea78eb 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1879,26 +1879,26 @@ virStorageAuthDefFree(virStorageAuthDefPtr authdef)
 virStorageAuthDefPtr
 virStorageAuthDefCopy(const virStorageAuthDef *src)
 {
-    virStorageAuthDefPtr ret;
+    virStorageAuthDefPtr authdef;
+    virStorageAuthDefPtr ret = NULL;
 
-    if (VIR_ALLOC(ret) < 0)
+    if (VIR_ALLOC(authdef) < 0)
         return NULL;
 
-    if (VIR_STRDUP(ret->username, src->username) < 0)
-        goto error;
+    if (VIR_STRDUP(authdef->username, src->username) < 0)
+        goto cleanup;
     /* Not present for storage pool, but used for disk source */
-    if (VIR_STRDUP(ret->secrettype, src->secrettype) < 0)
-        goto error;
-    ret->authType = src->authType;
+    if (VIR_STRDUP(authdef->secrettype, src->secrettype) < 0)
+        goto cleanup;
+    authdef->authType = src->authType;
 
-    if (virSecretLookupDefCopy(&ret->seclookupdef, &src->seclookupdef) < 0)
-        goto error;
+    if (virSecretLookupDefCopy(&authdef->seclookupdef, &src->seclookupdef) < 0)
+        goto cleanup;
 
+    VIR_STEAL_PTR(ret, authdef);
+ cleanup:
+    virStorageAuthDefFree(authdef);
     return ret;
-
- error:
-    virStorageAuthDefFree(ret);
-    return NULL;
 }
 
 
-- 
2.20.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