From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:57041) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TfeWo-0006G7-B9 for qemu-devel@nongnu.org; Mon, 03 Dec 2012 17:30:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TfeWn-0007Kc-5c for qemu-devel@nongnu.org; Mon, 03 Dec 2012 17:30:18 -0500 Sender: fluxion From: Michael Roth Date: Mon, 3 Dec 2012 16:25:48 -0600 Message-Id: <1354573559-26274-5-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1354573559-26274-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1354572547-21271-1-git-send-email-mdroth@linux.vnet.ibm.com> <1354573559-26274-1-git-send-email-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH 32/43] qom: fix refcount of non-heap-allocated objects List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-stable@nongnu.org Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org From: Paolo Bonzini 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. Acked-by: Andreas Färber Signed-off-by: Paolo Bonzini Signed-off-by: Anthony Liguori (cherry picked from commit 764b63125a77dab54ed405d493452a4e05679c2e) Signed-off-by: Michael Roth --- qom/object.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qom/object.c b/qom/object.c index f33e84d..5499318 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.7.9.5