From 0baf6945ed3b548a97be81402ffb1439cfc5c4da Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 22 Mar 2019 01:05:06 -0500 Subject: [PATCH] snapshot: Minor cleanup to virDomainSnapshotAssignDef 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 Signed-off-by: Eric Blake --- src/conf/virdomainsnapshotobjlist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conf/virdomainsnapshotobjlist.c b/src/conf/virdomainsnapshotobjlist.c index 7f2340404f..dbfacd8e49 100644 --- a/src/conf/virdomainsnapshotobjlist.c +++ b/src/conf/virdomainsnapshotobjlist.c @@ -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; }