From nobody Sun May 5 18:27:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500028538531979.0635619755469; Fri, 14 Jul 2017 03:35:38 -0700 (PDT) Received: from localhost ([::1]:36843 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVxwe-0007JT-59 for importer@patchew.org; Fri, 14 Jul 2017 06:35:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48592) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVxsW-0003mb-P0 for qemu-devel@nongnu.org; Fri, 14 Jul 2017 06:31:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVxsV-0007ki-Pt for qemu-devel@nongnu.org; Fri, 14 Jul 2017 06:31:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32905) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVxsR-0007jv-3z; Fri, 14 Jul 2017 06:31:15 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 122B864107; Fri, 14 Jul 2017 10:31:14 +0000 (UTC) Received: from t460.redhat.com (ovpn-117-13.ams2.redhat.com [10.36.117.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3FCF26E90A; Fri, 14 Jul 2017 10:31:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 122B864107 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=berrange@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 122B864107 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 11:31:05 +0100 Message-Id: <20170714103105.5781-1-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 14 Jul 2017 10:31:14 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] qcow: fix memory leaks related to encryption X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Fix leak of the 'encryptopts' string, which was mistakenly declared const. Fix leak of QemuOpts entry which should not have been deleted from the opts array. Reported by: coverity Signed-off-by: Daniel P. Berrange Reviewed-by: Eric Blake --- block/qcow.c | 5 +++-- block/qcow2.c | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index 66827d6f24..c08cdc4a7b 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -768,7 +768,7 @@ static int qcow_create(const char *filename, QemuOpts *= opts, Error **errp) Error *local_err =3D NULL; int ret; BlockBackend *qcow_blk; - const char *encryptfmt =3D NULL; + char *encryptfmt =3D NULL; QDict *options; QDict *encryptopts =3D NULL; QCryptoBlockCreateOptions *crypto_opts =3D NULL; @@ -793,7 +793,7 @@ static int qcow_create(const char *filename, QemuOpts *= opts, Error **errp) goto cleanup; } } else if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) { - encryptfmt =3D "aes"; + encryptfmt =3D g_strdup("aes"); } =20 ret =3D bdrv_create_file(filename, opts, &local_err); @@ -908,6 +908,7 @@ exit: blk_unref(qcow_blk); cleanup: QDECREF(encryptopts); + g_free(encryptfmt); qcrypto_block_free(crypto); qapi_free_QCryptoBlockCreateOptions(crypto_opts); g_free(backing_file); diff --git a/block/qcow2.c b/block/qcow2.c index c144ea5620..75d3e3c731 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2905,7 +2905,7 @@ static int qcow2_create(const char *filename, QemuOpt= s *opts, Error **errp) int version; uint64_t refcount_bits; int refcount_order; - const char *encryptfmt =3D NULL; + char *encryptfmt =3D NULL; Error *local_err =3D NULL; int ret; =20 @@ -2916,14 +2916,14 @@ static int qcow2_create(const char *filename, QemuO= pts *opts, Error **errp) backing_fmt =3D qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FMT); encryptfmt =3D qemu_opt_get_del(opts, BLOCK_OPT_ENCRYPT_FORMAT); if (encryptfmt) { - if (qemu_opt_get_del(opts, BLOCK_OPT_ENCRYPT)) { + if (qemu_opt_get(opts, BLOCK_OPT_ENCRYPT)) { error_setg(errp, "Options " BLOCK_OPT_ENCRYPT " and " BLOCK_OPT_ENCRYPT_FORMAT " are mutually exclusive"); ret =3D -EINVAL; goto finish; } } else if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) { - encryptfmt =3D "aes"; + encryptfmt =3D g_strdup("aes"); } cluster_size =3D qcow2_opt_get_cluster_size_del(opts, &local_err); if (local_err) { @@ -2983,6 +2983,7 @@ static int qcow2_create(const char *filename, QemuOpt= s *opts, Error **errp) finish: g_free(backing_file); g_free(backing_fmt); + g_free(encryptfmt); g_free(buf); return ret; } --=20 2.13.0