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é <f4...@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