From patchwork Fri Nov 23 08:47:12 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 201264 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 981872C0093 for ; Fri, 23 Nov 2012 19:55:48 +1100 (EST) Received: from localhost ([::1]:35934 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tbovn-0005i5-I1 for incoming@patchwork.ozlabs.org; Fri, 23 Nov 2012 03:48:15 -0500 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=cy3SUjbmN+1YGeWji3xkKkRQ+PqIKKlVW0tBgtNuGN4=; b=Uo2c72DFq89eDuNtF6Ku7WnQxlX/xFaLTPGEjyh5bv8PM7T5QZbshOyrBP3wcsKAhy c3avmojVjwjZFa25+iLJVar0ZI4/O1vkTRLC9b5KMNc8Ex7R1u6eLHMXM7TXqmBEnhw6 G+82j8rBH+I80wHX3NyJOeGBqj0pauQ3z5Izwsa31cRZmXqgMzJZhyTjMpknSgs31MIY qIpTVjjmibtjqFpLETTWtdws3q3RnrT65tH6KcmCDANbMIPAxYzYdNlCZ4eDjYrS6smm q2bw70R5qpawuBEKtw0g8EU+w5CZBr9wJwBBJ0wdI5zI2mXOkUETmQPwkW26eYKw41UZ t+Ew== Received: by 10.180.92.103 with SMTP id cl7mr4866143wib.16.1353660443486; Fri, 23 Nov 2012 00:47:23 -0800 (PST) Received: from yakj.lan (93-34-169-1.ip50.fastwebnet.it. [93.34.169.1]) by mx.google.com with ESMTPS id p3sm7581141wic.8.2012.11.23.00.47.21 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 23 Nov 2012 00:47:22 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 23 Nov 2012 09:47:12 +0100 Message-Id: <1353660436-8897-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.0 In-Reply-To: <1353660436-8897-1-git-send-email-pbonzini@redhat.com> References: <1353660436-8897-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.212.169 Cc: peter.maydell@linaro.org, aliguori@us.ibm.com, Liu Ping Fan Subject: [Qemu-devel] [PATCH 1.3 1/5] qom: fix refcount of non-heap-allocated objects X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Acked-by: Andreas Färber --- 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; }