* [Qemu-devel] [PATCH] qcow: fix memory leaks related to encryption
@ 2017-07-14 10:31 Daniel P. Berrange
2017-07-14 12:41 ` Eric Blake
2017-07-14 15:59 ` Max Reitz
0 siblings, 2 replies; 3+ messages in thread
From: Daniel P. Berrange @ 2017-07-14 10:31 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Max Reitz, qemu-block, Daniel P. Berrange
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>
---
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 = 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 c144ea5620..75d3e3c731 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.13.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] qcow: fix memory leaks related to encryption
2017-07-14 10:31 [Qemu-devel] [PATCH] qcow: fix memory leaks related to encryption Daniel P. Berrange
@ 2017-07-14 12:41 ` Eric Blake
2017-07-14 15:59 ` Max Reitz
1 sibling, 0 replies; 3+ messages in thread
From: Eric Blake @ 2017-07-14 12:41 UTC (permalink / raw)
To: Daniel P. Berrange, qemu-devel; +Cc: Kevin Wolf, qemu-block, Max Reitz
[-- Attachment #1: Type: text/plain, Size: 614 bytes --]
On 07/14/2017 05:31 AM, Daniel P. Berrange wrote:
> 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>
> ---
> block/qcow.c | 5 +++--
> block/qcow2.c | 7 ++++---
> 2 files changed, 7 insertions(+), 5 deletions(-)
>
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] qcow: fix memory leaks related to encryption
2017-07-14 10:31 [Qemu-devel] [PATCH] qcow: fix memory leaks related to encryption Daniel P. Berrange
2017-07-14 12:41 ` Eric Blake
@ 2017-07-14 15:59 ` Max Reitz
1 sibling, 0 replies; 3+ messages in thread
From: Max Reitz @ 2017-07-14 15:59 UTC (permalink / raw)
To: Daniel P. Berrange, qemu-devel; +Cc: Kevin Wolf, qemu-block
[-- Attachment #1: Type: text/plain, Size: 525 bytes --]
On 2017-07-14 12:31, Daniel P. Berrange wrote:
> 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>
> ---
> block/qcow.c | 5 +++--
> block/qcow2.c | 7 ++++---
> 2 files changed, 7 insertions(+), 5 deletions(-)
Thanks, applied to my block branch:
https://github.com/XanClic/qemu/commits/block
Max
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 498 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-07-14 15:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-14 10:31 [Qemu-devel] [PATCH] qcow: fix memory leaks related to encryption Daniel P. Berrange
2017-07-14 12:41 ` Eric Blake
2017-07-14 15:59 ` Max Reitz
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).