From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48768) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WuhVW-00088F-D2 for qemu-devel@nongnu.org; Wed, 11 Jun 2014 08:20:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WuhVN-0001Rt-6r for qemu-devel@nongnu.org; Wed, 11 Jun 2014 08:19:58 -0400 Received: from mail-wi0-x22c.google.com ([2a00:1450:400c:c05::22c]:43132) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WuhVN-0001RS-0v for qemu-devel@nongnu.org; Wed, 11 Jun 2014 08:19:49 -0400 Received: by mail-wi0-f172.google.com with SMTP id hi2so5656474wib.5 for ; Wed, 11 Jun 2014 05:19:46 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Wed, 11 Jun 2014 14:19:26 +0200 Message-Id: <1402489176-19738-4-git-send-email-pbonzini@redhat.com> In-Reply-To: <1402489176-19738-1-git-send-email-pbonzini@redhat.com> References: <1402489176-19738-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [RFC PATCH 03/13] qom: 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, afaerber@suse.de 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. 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 01087e5..69a95d6 100644 --- a/qom/object.c +++ b/qom/object.c @@ -386,19 +386,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) @@ -1017,6 +1007,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