From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:54719) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tbov5-0004BW-7f for qemu-devel@nongnu.org; Fri, 23 Nov 2012 03:47:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tbouy-0002kL-FB for qemu-devel@nongnu.org; Fri, 23 Nov 2012 03:47:31 -0500 Received: from mail-wi0-f169.google.com ([209.85.212.169]:44456) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tbouy-0002kC-8j for qemu-devel@nongnu.org; Fri, 23 Nov 2012 03:47:24 -0500 Received: by mail-wi0-f169.google.com with SMTP id hq12so1070629wib.4 for ; Fri, 23 Nov 2012 00:47:23 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Fri, 23 Nov 2012 09:47:12 +0100 Message-Id: <1353660436-8897-2-git-send-email-pbonzini@redhat.com> In-Reply-To: <1353660436-8897-1-git-send-email-pbonzini@redhat.com> References: <1353660436-8897-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 1.3 1/5] qom: fix refcount of non-heap-allocated objects List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, aliguori@us.ibm.com, Liu Ping Fan The reference count for embedded objects is always one too low, because object_initialize_with_type returns with zero references to the object. This causes premature finalization of the object (or an assertion failure) after calling object_ref to add an extra reference and object_unref to remove it. The fix is to move the initial object_ref call from object_new_with_type to object_initialize_with_type. Signed-off-by: Paolo Bonzini --- qom/object.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qom/object.c b/qom/object.c index d7092b0..6a8c02a 100644 --- a/qom/object.c +++ b/qom/object.c @@ -307,6 +307,7 @@ void object_initialize_with_type(void *data, TypeImpl *type) memset(obj, 0, type->instance_size); obj->class = type->class; + object_ref(obj); QTAILQ_INIT(&obj->properties); object_init_with_type(obj, type); } @@ -395,7 +396,6 @@ Object *object_new_with_type(Type type) obj = g_malloc(type->instance_size); object_initialize_with_type(obj, type); - object_ref(obj); return obj; } -- 1.8.0