Received: from eggs.gnu.org ([2001:4830:134:3::10]:35534) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XCR6Z-0000sp-JN for qemu-devel@nongnu.org; Wed, 30 Jul 2014 06:27:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XCR6Q-0000x4-Ii for qemu-devel@nongnu.org; Wed, 30 Jul 2014 06:27:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:4627) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XCR6Q-0000wk-Bz for qemu-devel@nongnu.org; Wed, 30 Jul 2014 06:27:22 -0400 From: Paolo Bonzini Date: Wed, 30 Jul 2014 12:27:05 +0200 Message-Id: <1406716032-21795-3-git-send-email-pbonzini@redhat.com> In-Reply-To: <1406716032-21795-1-git-send-email-pbonzini@redhat.com> References: <1406716032-21795-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 2/9] qom: object: move unparenting to the child property's release callback List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.crosthwaite@xilinx.com 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(-) diff --git a/qom/object.c b/qom/object.c index f301bc2..1b00831 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); } -- 1.8.3.1