[libvirt] [PATCH 6/8] secret: Have virSecretObjNew consume newdef

John Ferlan jferlan at redhat.com
Sat Jun 3 13:27:35 UTC 2017


Move the consumption of @newdef into virSecretObjNew and then handle that
in the calling path.  Because on error the calling code expects to free
@newdef, unset obj->def for the creation failure error paths.

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 src/conf/virsecretobj.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c
index c0bcfab..ca13cf8 100644
--- a/src/conf/virsecretobj.c
+++ b/src/conf/virsecretobj.c
@@ -87,7 +87,7 @@ virSecretObjOnceInit(void)
 VIR_ONCE_GLOBAL_INIT(virSecretObj)
 
 static virSecretObjPtr
-virSecretObjNew(void)
+virSecretObjNew(virSecretDefPtr def)
 {
     virSecretObjPtr obj;
 
@@ -98,6 +98,7 @@ virSecretObjNew(void)
         return NULL;
 
     virObjectLock(obj);
+    obj->def = def;
 
     return obj;
 }
@@ -384,20 +385,23 @@ virSecretObjListAdd(virSecretObjListPtr secrets,
         goto error;
     }
 
-    if (!(obj = virSecretObjNew()))
+    if (!(obj = virSecretObjNew(newdef)))
         goto cleanup;
 
     /* Generate the possible configFile and base64File strings
      * using the configDir, uuidstr, and appropriate suffix
      */
     if (!(obj->configFile = virFileBuildPath(configDir, uuidstr, ".xml")) ||
-        !(obj->base64File = virFileBuildPath(configDir, uuidstr, ".base64")))
+        !(obj->base64File = virFileBuildPath(configDir, uuidstr, ".base64"))) {
+        obj->def = NULL;
         goto error;
+    }
 
-    if (virHashAddEntry(secrets->objs, uuidstr, obj) < 0)
+    if (virHashAddEntry(secrets->objs, uuidstr, obj) < 0) {
+        obj->def = NULL;
         goto error;
+    }
 
-    obj->def = newdef;
     virObjectRef(obj);
 
  cleanup:
-- 
2.9.4




More information about the libvir-list mailing list