From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55566) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZYwRk-0004ci-J5 for qemu-devel@nongnu.org; Mon, 07 Sep 2015 09:26:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZYwRj-0005Ui-LI for qemu-devel@nongnu.org; Mon, 07 Sep 2015 09:26:56 -0400 From: Kevin Wolf Date: Mon, 7 Sep 2015 15:26:17 +0200 Message-Id: <1441632381-26638-10-git-send-email-kwolf@redhat.com> In-Reply-To: <1441632381-26638-1-git-send-email-kwolf@redhat.com> References: <1441632381-26638-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH v3 09/13] qcow2: Fix memory leak in qcow2_update_options() error path List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Max Reitz --- block/qcow2.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 923b9dd..226b1b1 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -597,8 +597,8 @@ static int qcow2_update_options(BlockDriverState *bs, QDict *options, const char *opt_overlap_check, *opt_overlap_check_template; int overlap_check_template = 0; uint64_t l2_cache_size, refcount_cache_size; - Qcow2Cache *l2_table_cache; - Qcow2Cache *refcount_block_cache; + Qcow2Cache *l2_table_cache = NULL; + Qcow2Cache *refcount_block_cache = NULL; uint64_t cache_clean_interval; bool use_lazy_refcounts; int i; @@ -735,6 +735,14 @@ static int qcow2_update_options(BlockDriverState *bs, QDict *options, ret = 0; fail: + if (ret < 0) { + if (l2_table_cache) { + qcow2_cache_destroy(bs, l2_table_cache); + } + if (refcount_block_cache) { + qcow2_cache_destroy(bs, refcount_block_cache); + } + } qemu_opts_del(opts); opts = NULL; -- 1.8.3.1