From patchwork Thu Nov 7 13:12:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 289339 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D12A82C00DE for ; Fri, 8 Nov 2013 00:46:34 +1100 (EST) Received: from localhost ([::1]:40394 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VePuq-000246-QF for incoming@patchwork.ozlabs.org; Thu, 07 Nov 2013 08:46:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58451) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VePtC-0000H0-DW for qemu-devel@nongnu.org; Thu, 07 Nov 2013 08:44:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VePt4-0007os-0f for qemu-devel@nongnu.org; Thu, 07 Nov 2013 08:44:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:24078) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VePt3-0007k8-OZ for qemu-devel@nongnu.org; Thu, 07 Nov 2013 08:44:41 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rA7DDKGX021185 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 7 Nov 2013 08:13:21 -0500 Received: from localhost (ovpn-112-18.ams2.redhat.com [10.36.112.18]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rA7DDJEu029094; Thu, 7 Nov 2013 08:13:20 -0500 From: Stefan Hajnoczi To: Date: Thu, 7 Nov 2013 14:12:19 +0100 Message-Id: <1383829964-32364-12-git-send-email-stefanha@redhat.com> In-Reply-To: <1383829964-32364-1-git-send-email-stefanha@redhat.com> References: <1383829964-32364-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Stefan Hajnoczi , Anthony Liguori Subject: [Qemu-devel] [PULL 11/36] blockdev: fix drive_init() opts and bs_opts leaks 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 These memory leaks also make drive_add if=none,id=drive0 without a file= option leak the options list. This keeps ID "drive0" around forever. Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake --- blockdev.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/blockdev.c b/blockdev.c index b260477..86e6bff 100644 --- a/blockdev.c +++ b/blockdev.c @@ -341,7 +341,7 @@ static DriveInfo *blockdev_init(QDict *bs_opts, qemu_opts_absorb_qdict(opts, bs_opts, &error); if (error_is_set(&error)) { error_propagate(errp, error); - return NULL; + goto early_err; } if (id) { @@ -361,7 +361,7 @@ static DriveInfo *blockdev_init(QDict *bs_opts, if ((buf = qemu_opt_get(opts, "discard")) != NULL) { if (bdrv_parse_discard_flags(buf, &bdrv_flags) != 0) { error_setg(errp, "invalid discard option"); - return NULL; + goto early_err; } } @@ -383,7 +383,7 @@ static DriveInfo *blockdev_init(QDict *bs_opts, /* this is the default */ } else { error_setg(errp, "invalid aio option"); - return NULL; + goto early_err; } } #endif @@ -393,13 +393,13 @@ static DriveInfo *blockdev_init(QDict *bs_opts, error_printf("Supported formats:"); bdrv_iterate_format(bdrv_format_print, NULL); error_printf("\n"); - return NULL; + goto early_err; } drv = bdrv_find_format(buf); if (!drv) { error_setg(errp, "'%s' invalid format", buf); - return NULL; + goto early_err; } } @@ -435,20 +435,20 @@ static DriveInfo *blockdev_init(QDict *bs_opts, if (!check_throttle_config(&cfg, &error)) { error_propagate(errp, error); - return NULL; + goto early_err; } on_write_error = BLOCKDEV_ON_ERROR_ENOSPC; if ((buf = qemu_opt_get(opts, "werror")) != NULL) { if (type != IF_IDE && type != IF_SCSI && type != IF_VIRTIO && type != IF_NONE) { error_setg(errp, "werror is not supported by this bus type"); - return NULL; + goto early_err; } on_write_error = parse_block_error_action(buf, 0, &error); if (error_is_set(&error)) { error_propagate(errp, error); - return NULL; + goto early_err; } } @@ -456,13 +456,13 @@ static DriveInfo *blockdev_init(QDict *bs_opts, if ((buf = qemu_opt_get(opts, "rerror")) != NULL) { if (type != IF_IDE && type != IF_VIRTIO && type != IF_SCSI && type != IF_NONE) { error_report("rerror is not supported by this bus type"); - return NULL; + goto early_err; } on_read_error = parse_block_error_action(buf, 1, &error); if (error_is_set(&error)) { error_propagate(errp, error); - return NULL; + goto early_err; } } @@ -491,6 +491,8 @@ static DriveInfo *blockdev_init(QDict *bs_opts, if (has_driver_specific_opts) { file = NULL; } else { + QDECREF(bs_opts); + qemu_opts_del(opts); return dinfo; } } @@ -529,12 +531,13 @@ static DriveInfo *blockdev_init(QDict *bs_opts, return dinfo; err: - qemu_opts_del(opts); - QDECREF(bs_opts); bdrv_unref(dinfo->bdrv); g_free(dinfo->id); QTAILQ_REMOVE(&drives, dinfo, next); g_free(dinfo); +early_err: + QDECREF(bs_opts); + qemu_opts_del(opts); return NULL; }