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

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

 



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@xxxxxxxxxx>
---
 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

--
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