]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Fix error path logic in virDomainObjListAddLocked
authorJohn Ferlan <jferlan@redhat.com>
Mon, 26 Mar 2018 22:29:30 +0000 (18:29 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Fri, 6 Apr 2018 18:14:31 +0000 (14:14 -0400)
If the virHashAddEntry fails, then we need to "careful" about
how we free the @vm. When virDomainObjNew returns there is one
reference and the object is locked, so use virDomainObjEndAPI
when done.

Add a virObjectRef in the error path for the second virHashAddEntry
call since it doesn't call virObjectRef, but virHashRemoveEntry
will call virObjectUnref because virObjectFreeHashData is called
when the element is removed from the hash table as set up in
virDomainObjListNew.

Eventually these paths should goto error and error should be changed
to use EndAPI as well, but that requires more adjustments to other
paths in the code to have a locked and ref counted @vm.

Signed-off-by: John Ferlan <jferlan@redhat.com>
src/conf/virdomainobjlist.c

index 87a742b1ea2799ac41fbe5aaad93740ff8a0c0f1..aa7966e364436eb8c350d556ffdeae5caa514338 100644 (file)
@@ -296,12 +296,14 @@ virDomainObjListAddLocked(virDomainObjListPtr doms,
 
         virUUIDFormat(def->uuid, uuidstr);
         if (virHashAddEntry(doms->objs, uuidstr, vm) < 0) {
-            virObjectUnref(vm);
+            virDomainObjEndAPI(&vm);
             return NULL;
         }
 
         if (virHashAddEntry(doms->objsName, def->name, vm) < 0) {
+            virObjectRef(vm);
             virHashRemoveEntry(doms->objs, uuidstr);
+            virDomainObjEndAPI(&vm);
             return NULL;
         }