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>
goto error;
if (virHashAddEntry(doms->objsName, obj->def->name, obj) < 0) {
+ virObjectRef(obj);
virHashRemoveEntry(doms->objs, uuidstr);
goto error;
}
return obj;
error:
- virObjectUnref(obj);
+ virDomainObjEndAPI(&obj);
VIR_FREE(statusFile);
return NULL;
}