[libvirt] [PATCH v2 2/4] secret: Remove need for local configFile and base64File in ObjectAdd

John Ferlan posted 4 patches 7 years, 10 months ago
There is a newer version of this series
[libvirt] [PATCH v2 2/4] secret: Remove need for local configFile and base64File in ObjectAdd
Posted by John Ferlan 7 years, 10 months ago
Rather than assign to a local variable, let's just assign directly to the
object using the error path for cleanup.

Signed-off-by: John Ferlan <jferlan@redhat.com>
---
 src/conf/virsecretobj.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c
index bedcdbd..dd36ce6 100644
--- a/src/conf/virsecretobj.c
+++ b/src/conf/virsecretobj.c
@@ -334,7 +334,6 @@ virSecretObjListAdd(virSecretObjListPtr secrets,
     virSecretObjPtr obj;
     virSecretDefPtr objdef;
     char uuidstr[VIR_UUID_STRING_BUFLEN];
-    char *configFile = NULL, *base64File = NULL;
 
     virObjectLock(secrets);
 
@@ -384,28 +383,24 @@ virSecretObjListAdd(virSecretObjListPtr secrets,
             goto error;
         }
 
+        if (!(obj = virSecretObjNew()))
+            goto cleanup;
+
         /* Generate the possible configFile and base64File strings
          * using the configDir, uuidstr, and appropriate suffix
          */
-        if (!(configFile = virFileBuildPath(configDir, uuidstr, ".xml")) ||
-            !(base64File = virFileBuildPath(configDir, uuidstr, ".base64")))
-            goto cleanup;
-
-        if (!(obj = virSecretObjNew()))
-            goto cleanup;
+        if (!(obj->configFile = virFileBuildPath(configDir, uuidstr, ".xml")) ||
+            !(obj->base64File = virFileBuildPath(configDir, uuidstr, ".base64")))
+            goto error;
 
         if (virHashAddEntry(secrets->objs, uuidstr, obj) < 0)
             goto error;
 
         obj->def = newdef;
-        VIR_STEAL_PTR(obj->configFile, configFile);
-        VIR_STEAL_PTR(obj->base64File, base64File);
         virObjectRef(obj);
     }
 
  cleanup:
-    VIR_FREE(configFile);
-    VIR_FREE(base64File);
     virObjectUnlock(secrets);
     return obj;
 
-- 
2.9.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 2/4] secret: Remove need for local configFile and base64File in ObjectAdd
Posted by Pavel Hrdina 7 years, 9 months ago
On Fri, Jul 14, 2017 at 10:04:40AM -0400, John Ferlan wrote:
> Rather than assign to a local variable, let's just assign directly to the
> object using the error path for cleanup.
> 
> Signed-off-by: John Ferlan <jferlan@redhat.com>
> ---
>  src/conf/virsecretobj.c | 17 ++++++-----------
>  1 file changed, 6 insertions(+), 11 deletions(-)

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list