From 76a6e1cc7cc3ad022e7159b37b291b75bc4615bf Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 11 Jun 2014 11:58:30 +0200 Subject: qom: object: delete properties before calling instance_finalize This ensures that the children's unparent callback will still have a usable parent. Reviewed-by: Peter Crosthwaite Signed-off-by: Paolo Bonzini --- qom/object.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'qom') diff --git a/qom/object.c b/qom/object.c index 0e8267bc2a..f301bc2abb 100644 --- a/qom/object.c +++ b/qom/object.c @@ -418,8 +418,8 @@ static void object_finalize(void *data) Object *obj = data; TypeImpl *ti = obj->class->type; - object_deinit(obj, ti); object_property_del_all(obj); + object_deinit(obj, ti); g_assert(obj->ref == 0); if (obj->free) { -- cgit v1.2.3 From bffc687d66604e68c14f6277b595b33966eb328a Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 11 Jun 2014 11:57:38 +0200 Subject: qom: object: move unparenting to the child property's release callback This ensures that the unparent callback is called automatically when the parent object is finalized. Note that there's no need to keep a reference neither in object_unparent nor in object_finalize_child_property. The reference held by the child property itself will do. Reviewed-by: Peter Crosthwaite Signed-off-by: Paolo Bonzini --- qom/object.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'qom') diff --git a/qom/object.c b/qom/object.c index f301bc2abb..1b00831efc 100644 --- a/qom/object.c +++ b/qom/object.c @@ -387,19 +387,9 @@ static void object_property_del_child(Object *obj, Object *child, Error **errp) void object_unparent(Object *obj) { - if (!obj->parent) { - return; - } - - object_ref(obj); - if (obj->class->unparent) { - (obj->class->unparent)(obj); - } if (obj->parent) { object_property_del_child(obj->parent, obj, NULL); - obj->parent = NULL; } - object_unref(obj); } static void object_deinit(Object *obj, TypeImpl *type) @@ -1042,6 +1032,10 @@ static void object_finalize_child_property(Object *obj, const char *name, { Object *child = opaque; + if (child->class->unparent) { + (child->class->unparent)(child); + } + child->parent = NULL; object_unref(child); } -- cgit v1.2.3