]> xenbits.xensource.com Git - libvirt.git/commitdiff
snapshot: Minor cleanup to virDomainSnapshotAssignDef
authorEric Blake <eblake@redhat.com>
Fri, 22 Mar 2019 06:05:06 +0000 (01:05 -0500)
committerEric Blake <eblake@redhat.com>
Fri, 22 Mar 2019 06:15:20 +0000 (01:15 -0500)
When a future patch converts virDomainSnapshotDef to be a virObject,
we need to be careful that converting VIR_FREE() to virObjectUnref()
does not result in double frees. Reorder the assignment of def into
the object to the point after object is in the hash table (as
otherwise the virHashAddEntry() error path would have a shot at
freeing def prematurely).

Suggested-by: John Ferlan <ferlan@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
src/conf/virdomainsnapshotobjlist.c

index 7f2340404f1427cf165754f32e0d9b0f4c5a06a4..dbfacd8e49f52d5c7f50a5b5724760892887449a 100644 (file)
@@ -250,12 +250,12 @@ virDomainSnapshotObjPtr virDomainSnapshotAssignDef(virDomainSnapshotObjListPtr s
 
     if (!(snap = virDomainSnapshotObjNew()))
         return NULL;
-    snap->def = def;
 
     if (virHashAddEntry(snapshots->objs, snap->def->name, snap) < 0) {
         VIR_FREE(snap);
         return NULL;
     }
+    snap->def = def;
 
     return snap;
 }