aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2020-05-05 17:29:09 +0200
committerMarkus Armbruster <armbru@redhat.com>2020-05-15 06:26:02 +0200
commit975ac4559c4c00010e05f7a3e782eeb9497837ea (patch)
tree1100f05f25cfdaa6f2aa3beda38e65d7a978ebba
parent013a18edbbc59cdad019100c7d03c0494642b74c (diff)
qom: Clearer reference counting in object_initialize_childv()
Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Message-Id: <20200505152926.18877-2-armbru@redhat.com>
-rw-r--r--qom/object.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/qom/object.c b/qom/object.c
index be700e831f..5511649502 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -571,18 +571,18 @@ void object_initialize_childv(Object *parentobj, const char *propname,
}
}
+out:
/*
- * Since object_property_add_child added a reference to the child object,
- * we can drop the reference added by object_initialize(), so the child
- * property will own the only reference to the object.
+ * We want @obj's reference to be 1 on success, 0 on failure.
+ * On success, it's 2: one taken by object_initialize(), and one
+ * by object_property_add_child().
+ * On failure in object_initialize() or earlier, it's 1.
+ * On failure afterwards, it's also 1: object_unparent() releases
+ * the reference taken by object_property_add_child().
*/
object_unref(obj);
-out:
- if (local_err) {
- error_propagate(errp, local_err);
- object_unref(obj);
- }
+ error_propagate(errp, local_err);
}
static inline bool object_property_is_child(ObjectProperty *prop)