From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>
Cc: "Philippe Mathieu-Daudé" <f4bug@amsat.org>,
qemu-devel@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>,
qemu-block@nongnu.org, "Markus Armbruster" <armbru@redhat.com>,
"Eric Blake" <eblake@redhat.com>
Subject: [Qemu-devel] [PATCH] block/crypto: Simplify block_crypto_co_create_opts_luks to avoid a memory leak
Date: Wed, 4 Jul 2018 12:02:29 -0300 [thread overview]
Message-ID: <20180704150229.9948-1-f4bug@amsat.org> (raw)
After 1ec4f4160a1 Coverity reported:
Variable cryptoopts going out of scope leaks the storage it points to.
Fixes: Coverity CID 1393782 (Resource leak)
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
I think this check is superfluous but I respected the previous code:
ret = block_crypto_co_create_generic(bs, size, create_opts, errp);
if (ret > 0) {
ret = 0;
}
block/crypto.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/block/crypto.c b/block/crypto.c
index 994172a3de..d4d2c6c511 100644
--- a/block/crypto.c
+++ b/block/crypto.c
@@ -545,33 +545,36 @@ static int coroutine_fn block_crypto_co_create_opts_luks(const char *filename,
create_opts = block_crypto_create_opts_init(cryptoopts, errp);
if (!create_opts) {
ret = -EINVAL;
- goto fail;
+ goto cleanup_cryptoopts;
}
/* Create protocol layer */
ret = bdrv_create_file(filename, opts, errp);
if (ret < 0) {
- return ret;
+ goto cleanup_create_opts;
}
bs = bdrv_open(filename, NULL, NULL,
BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL, errp);
if (!bs) {
ret = -EINVAL;
- goto fail;
+ goto cleanup_create_opts;
}
/* Create format layer */
ret = block_crypto_co_create_generic(bs, size, create_opts, errp);
- if (ret < 0) {
- goto fail;
+ if (ret > 0) {
+ ret = 0;
}
- ret = 0;
-fail:
bdrv_unref(bs);
+
+cleanup_create_opts:
qapi_free_QCryptoBlockCreateOptions(create_opts);
+
+cleanup_cryptoopts:
qobject_unref(cryptoopts);
+
return ret;
}
--
2.18.0
next reply other threads:[~2018-07-04 15:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-04 15:02 Philippe Mathieu-Daudé [this message]
2018-07-05 10:20 ` [Qemu-devel] [PATCH] block/crypto: Simplify block_crypto_co_create_opts_luks to avoid a memory leak Kevin Wolf
2018-07-05 16:04 ` Philippe Mathieu-Daudé
2018-07-05 16:21 ` Kevin Wolf
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=20180704150229.9948-1-f4bug@amsat.org \
--to=f4bug@amsat.org \
--cc=armbru@redhat.com \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--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).