From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47663) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XW22Q-0006dS-IX for qemu-devel@nongnu.org; Mon, 22 Sep 2014 07:44:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XW22L-00088D-CB for qemu-devel@nongnu.org; Mon, 22 Sep 2014 07:44:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:22359) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XW22L-00086v-3m for qemu-devel@nongnu.org; Mon, 22 Sep 2014 07:44:09 -0400 From: Stefan Hajnoczi Date: Mon, 22 Sep 2014 12:42:09 +0100 Message-Id: <1411386150-24003-39-git-send-email-stefanha@redhat.com> In-Reply-To: <1411386150-24003-1-git-send-email-stefanha@redhat.com> References: <1411386150-24003-1-git-send-email-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL v2 38/59] qcow2: Fix leak of QemuOpts in qcow2_open() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Stefan Hajnoczi , Max Reitz From: Max Reitz Currently, the QemuOpts object opts is leaked if anything fails from its creation up to and including the image repair block. Fix this by freeing that object in the fail path. Signed-off-by: Max Reitz Reviewed-by: Eric Blake Reviewed-by: Beno=C3=AEt Canet Message-id: 1408557576-14574-2-git-send-email-mreitz@redhat.com Signed-off-by: Stefan Hajnoczi --- block/qcow2.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index f4bbe8b..744e0db 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -538,7 +538,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *op= tions, int flags, unsigned int len, i; int ret =3D 0; QCowHeader header; - QemuOpts *opts; + QemuOpts *opts =3D NULL; Error *local_err =3D NULL; uint64_t ext_end; uint64_t l1_vm_state_index; @@ -935,7 +935,6 @@ static int qcow2_open(BlockDriverState *bs, QDict *op= tions, int flags, error_setg(errp, "Unsupported value '%s' for qcow2 option " "'overlap-check'. Allowed are either of the following= : " "none, constant, cached, all", opt_overlap_check); - qemu_opts_del(opts); ret =3D -EINVAL; goto fail; } @@ -950,6 +949,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *op= tions, int flags, } =20 qemu_opts_del(opts); + opts =3D NULL; =20 if (s->use_lazy_refcounts && s->qcow_version < 3) { error_setg(errp, "Lazy refcounts require a qcow2 image with at l= east " @@ -967,6 +967,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *op= tions, int flags, return ret; =20 fail: + qemu_opts_del(opts); g_free(s->unknown_header_fields); cleanup_unknown_header_ext(bs); qcow2_free_snapshots(bs); --=20 1.9.3