From patchwork Thu May 3 02:42:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Baron X-Patchwork-Id: 156597 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 04B54B6FBA for ; Thu, 3 May 2012 12:42:28 +1000 (EST) Received: from localhost ([::1]:37021 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SPlzt-0006Cz-KU for incoming@patchwork.ozlabs.org; Wed, 02 May 2012 22:42:25 -0400 Received: from eggs.gnu.org ([208.118.235.92]:41763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SPlzi-0006CI-Jk for qemu-devel@nongnu.org; Wed, 02 May 2012 22:42:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SPlzg-0004EH-S3 for qemu-devel@nongnu.org; Wed, 02 May 2012 22:42:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48689) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SPlzg-0004E4-KL for qemu-devel@nongnu.org; Wed, 02 May 2012 22:42:12 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q432gBiE026589 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 2 May 2012 22:42:11 -0400 Received: from redhat.com (vpn-10-160.rdu.redhat.com [10.11.10.160]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q432gAcc013071; Wed, 2 May 2012 22:42:10 -0400 Date: Wed, 2 May 2012 22:42:10 -0400 From: Jason Baron To: qemu-devel@nongnu.org Message-Id: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: pbonzini@redhat.com, alex.williamson@redhat.com, aliguori@us.ibm.com, mst@redhat.com Subject: [Qemu-devel] [PATCH 1/2] qdev: release parent properties on dc->init failure 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 While looking into hot-plugging bridges, I can create a qemu segfault via: $ device_add pci-bridge Bridge chassis not specified. Each bridge is required to be assigned a unique chassis id > 0. ** ERROR:qom/object.c:389:object_delete: assertion failed: (obj->ref == 0) I'm proposing to fix this by adding a call to 'object_unparent()', before the call to qdev_free(). I see there is already a precedent for this usage pattern as seen in qdev_simple_unplug_cb(): /* can be used as ->unplug() callback for the simple cases */ int qdev_simple_unplug_cb(DeviceState *dev) { /* just zap it */ object_unparent(OBJECT(dev)); qdev_free(dev); return 0; } Signed-off-by: Jason Baron --- hw/qdev.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index 0bcde20..cff7f4c 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -150,6 +150,7 @@ int qdev_init(DeviceState *dev) rc = dc->init(dev); if (rc < 0) { + object_unparent(OBJECT(dev)); qdev_free(dev); return rc; }