aboutsummaryrefslogtreecommitdiff
path: root/block/qcow2.c
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2017-07-14 11:31:05 +0100
committerMax Reitz <mreitz@redhat.com>2017-07-25 16:33:31 +0200
commit0696ae2c9236a3589f5eaf5b00c12868b6f30a17 (patch)
tree57aca1a5923eb3dc971fe1d51049f7cdd4bef5a1 /block/qcow2.c
parent4c4414a4388f902b7ae2814f9a64898dd0e426a5 (diff)
qcow: fix memory leaks related to encryption
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>
Diffstat (limited to 'block/qcow2.c')
-rw-r--r--block/qcow2.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/block/qcow2.c b/block/qcow2.c
index 90efa4477b..d7c600b5a2 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;
}