]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Fix error path logic in virDomainObjListLoadStatus
authorJohn Ferlan <jferlan@redhat.com>
Mon, 26 Mar 2018 23:14:30 +0000 (19:14 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Fri, 6 Apr 2018 18:14:37 +0000 (14:14 -0400)
If the virHashAddEntry fails, then we need to "careful" about
how we free the @obj. When virDomainObjParseFile 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.

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

index aa7966e364436eb8c350d556ffdeae5caa514338..259657918cab8a5421aff41651e0ead61b32a687 100644 (file)
@@ -536,6 +536,7 @@ virDomainObjListLoadStatus(virDomainObjListPtr doms,
         goto error;
 
     if (virHashAddEntry(doms->objsName, obj->def->name, obj) < 0) {
+        virObjectRef(obj);
         virHashRemoveEntry(doms->objs, uuidstr);
         goto error;
     }
@@ -551,7 +552,7 @@ virDomainObjListLoadStatus(virDomainObjListPtr doms,
     return obj;
 
  error:
-    virObjectUnref(obj);
+    virDomainObjEndAPI(&obj);
     VIR_FREE(statusFile);
     return NULL;
 }