From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=36852 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PnYmR-0000ch-0S for qemu-devel@nongnu.org; Thu, 10 Feb 2011 10:50:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PnYmJ-00082s-4v for qemu-devel@nongnu.org; Thu, 10 Feb 2011 10:49:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:32795) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PnYmI-00082h-Ty for qemu-devel@nongnu.org; Thu, 10 Feb 2011 10:49:55 -0500 From: Kevin Wolf Date: Thu, 10 Feb 2011 16:51:25 +0100 Message-Id: <1297353086-4844-11-git-send-email-kwolf@redhat.com> In-Reply-To: <1297353086-4844-1-git-send-email-kwolf@redhat.com> References: <1297353086-4844-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 10/11] blockdev: Plug memory leak in drive_init() error paths List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: Markus Armbruster Should have spotted this when doing commit 319ae529. Signed-off-by: Markus Armbruster Signed-off-by: Kevin Wolf --- blockdev.c | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-) diff --git a/blockdev.c b/blockdev.c index 24d7658..0690cc8 100644 --- a/blockdev.c +++ b/blockdev.c @@ -526,7 +526,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi) } else if (ro == 1) { if (type != IF_SCSI && type != IF_VIRTIO && type != IF_FLOPPY && type != IF_NONE) { error_report("readonly not supported by this bus type"); - return NULL; + goto err; } } @@ -536,12 +536,19 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi) if (ret < 0) { error_report("could not open disk image %s: %s", file, strerror(-ret)); - return NULL; + goto err; } if (bdrv_key_required(dinfo->bdrv)) autostart = 0; return dinfo; + +err: + bdrv_delete(dinfo->bdrv); + qemu_free(dinfo->id); + QTAILQ_REMOVE(&drives, dinfo, next); + qemu_free(dinfo); + return NULL; } void do_commit(Monitor *mon, const QDict *qdict) -- 1.7.2.3