From 0696ae2c9236a3589f5eaf5b00c12868b6f30a17 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Fri, 14 Jul 2017 11:31:05 +0100 Subject: 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 Message-id: 20170714103105.5781-1-berrange@redhat.com Reviewed-by: Eric Blake Signed-off-by: Max Reitz --- block/qcow.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'block/qcow.c') 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); -- cgit v1.2.1