qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Lukáš Doktor" <ldoktor@redhat.com>
To: qemu-devel@nongnu.org
Cc: ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com,
	armbru@redhat.com, apahim@redhat.com, f4bug@amsat.org,
	mreitz@redhat.com, jsnow@redhat.com,
	"Daniel P. Berrange" <berrange@redhat.com>
Subject: [Qemu-devel] [PATCH v3 01/14] qcow: fix memory leaks related to encryption
Date: Wed, 26 Jul 2017 16:35:30 +0200	[thread overview]
Message-ID: <20170726143543.2530-2-ldoktor@redhat.com> (raw)
In-Reply-To: <20170726143543.2530-1-ldoktor@redhat.com>

From: "Daniel P. Berrange" <berrange@redhat.com>

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 <berrange@redhat.com>
Message-id: 20170714103105.5781-1-berrange@redhat.com
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 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 66827d6..c08cdc4 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 = NULL;
     int ret;
     BlockBackend *qcow_blk;
-    const char *encryptfmt = NULL;
+    char *encryptfmt = NULL;
     QDict *options;
     QDict *encryptopts = NULL;
     QCryptoBlockCreateOptions *crypto_opts = 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 = "aes";
+        encryptfmt = g_strdup("aes");
     }
 
     ret = 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 90efa44..d7c600b 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2905,7 +2905,7 @@ static int qcow2_create(const char *filename, QemuOpts *opts, Error **errp)
     int version;
     uint64_t refcount_bits;
     int refcount_order;
-    const char *encryptfmt = NULL;
+    char *encryptfmt = NULL;
     Error *local_err = NULL;
     int ret;
 
@@ -2916,14 +2916,14 @@ static int qcow2_create(const char *filename, QemuOpts *opts, Error **errp)
     backing_fmt = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FMT);
     encryptfmt = 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 = -EINVAL;
             goto finish;
         }
     } else if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) {
-        encryptfmt = "aes";
+        encryptfmt = g_strdup("aes");
     }
     cluster_size = qcow2_opt_get_cluster_size_del(opts, &local_err);
     if (local_err) {
@@ -2983,6 +2983,7 @@ static int qcow2_create(const char *filename, QemuOpts *opts, Error **errp)
 finish:
     g_free(backing_file);
     g_free(backing_fmt);
+    g_free(encryptfmt);
     g_free(buf);
     return ret;
 }
-- 
2.9.4

  reply	other threads:[~2017-07-26 14:36 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-26 14:35 [Qemu-devel] [PATCH v3 00/14] qemu.py: Pylint/style fixes Lukáš Doktor
2017-07-26 14:35 ` Lukáš Doktor [this message]
2017-07-26 14:35 ` [Qemu-devel] [PATCH v3 02/14] qcow2-bitmap: fix bitmap_free Lukáš Doktor
2017-07-26 14:35 ` [Qemu-devel] [PATCH v3 03/14] qemu-iotests: Fix reference output for 186 Lukáš Doktor
2017-07-26 14:35 ` [Qemu-devel] [PATCH v3 04/14] Update version for v2.10.0-rc0 release Lukáš Doktor
2017-07-26 14:35 ` [Qemu-devel] [PATCH v3 05/14] qemu.py: Pylint/style fixes Lukáš Doktor
2017-07-26 14:35 ` [Qemu-devel] [PATCH v3 06/14] qemu|qtest: Avoid dangerous arguments Lukáš Doktor
2017-07-26 14:35 ` [Qemu-devel] [PATCH v3 07/14] qemu.py: Use iteritems rather than keys() Lukáš Doktor
2017-07-26 14:35 ` [Qemu-devel] [PATCH v3 08/14] qemu.py: Simplify QMP key-conversion Lukáš Doktor
2017-07-26 14:35 ` [Qemu-devel] [PATCH v3 09/14] qemu.py: Use custom exceptions rather than Exception Lukáš Doktor
2017-07-26 14:35 ` [Qemu-devel] [PATCH v3 10/14] qmp.py: Couple of pylint/style fixes Lukáš Doktor
2017-07-26 14:35 ` [Qemu-devel] [PATCH v3 11/14] qmp.py: Use object-based class for QEMUMonitorProtocol Lukáš Doktor
2017-07-26 14:35 ` [Qemu-devel] [PATCH v3 12/14] qmp.py: Avoid "has_key" usage Lukáš Doktor
2017-07-26 14:35 ` [Qemu-devel] [PATCH v3 13/14] qmp.py: Avoid overriding a builtin object Lukáš Doktor
2017-07-26 14:35 ` [Qemu-devel] [PATCH v3 14/14] qtest.py: Few pylint/style fixes Lukáš Doktor
2017-07-26 14:38 ` [Qemu-devel] [PATCH v3 00/14] qemu.py: Pylint/style fixes Lukáš Doktor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170726143543.2530-2-ldoktor@redhat.com \
    --to=ldoktor@redhat.com \
    --cc=apahim@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=f4bug@amsat.org \
    --cc=famz@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).