From patchwork Tue Feb 16 12:12:38 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 45463 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2D3D4B7C98 for ; Tue, 16 Feb 2010 23:15:57 +1100 (EST) Received: from localhost ([127.0.0.1]:50475 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NhMKI-0003iS-DL for incoming@patchwork.ozlabs.org; Tue, 16 Feb 2010 07:14:50 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NhMJ2-0003hD-Kk for qemu-devel@nongnu.org; Tue, 16 Feb 2010 07:13:32 -0500 Received: from [199.232.76.173] (port=41128 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NhMJ2-0003gx-9B for qemu-devel@nongnu.org; Tue, 16 Feb 2010 07:13:32 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NhMIy-0001mx-15 for qemu-devel@nongnu.org; Tue, 16 Feb 2010 07:13:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:7266) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NhMIx-0001mj-J6 for qemu-devel@nongnu.org; Tue, 16 Feb 2010 07:13:27 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o1GCDQ5v022531 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 16 Feb 2010 07:13:26 -0500 Received: from localhost.localdomain (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o1GCDOQA023822 for ; Tue, 16 Feb 2010 07:13:25 -0500 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Tue, 16 Feb 2010 13:12:38 +0100 Message-Id: <1266322358-7075-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH] qdev: Free opts on failed do_device_add X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org If the device can't be created, don't leak the QemuOpts and release the id of the device that should have been added by the failed device_add. Signed-off-by: Kevin Wolf Acked-by: Gerd Hoffmann --- hw/qdev.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index 539b5a2..d0052d4 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -749,8 +749,11 @@ void do_device_add(Monitor *mon, const QDict *qdict) opts = qemu_opts_parse(&qemu_device_opts, qdict_get_str(qdict, "config"), "driver"); - if (opts && !qdev_device_help(opts)) - qdev_device_add(opts); + if (opts) { + if (qdev_device_help(opts) || qdev_device_add(opts) == NULL) { + qemu_opts_del(opts); + } + } } void do_device_del(Monitor *mon, const QDict *qdict)