block: Fix leaks of opts in block drivers
v2 cover block: Fix leaks of opts in block drivers
Remember to call qemu_opts_del before function returning.
v2: Drop qcow2 fix since it's duplicated with Max's "[PATCH 0/4]
qapi/block-core: Add "new" qcow2 options" series. (Max) Fix nfs return code. (Benoit)
Add Beniot's rev-by lines in other patches. (Thanks for reviewing)
Fam Zheng (3):
nfs: Fix leak of opts in nfs_file_open
blkverify: Fix leak of opts in blkverify_open
quorum: Fix leak of opts in quorum_open
block/blkverify.c | 1 + block/nfs.c | 8 ++++++-- block/quorum.c | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-)
Signature · 1 line
2.1.0
PATCH v2 1/3 nfs: Fix leak of opts in nfs_file_open
--- block/nfs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
block/nfs.c +6 -2
@@ -393,15 +393,19 @@ static int nfs_file_open(BlockDriverState *bs, QDict *options, int flags,qemu_opts_absorb_qdict (opts, options, &local_err);if (local_err) {error_propagate (errp, local_err); -return -EINVAL ; + ret = -EINVAL ; + goto out; } ret =nfs_client_open (client,qemu_opt_get (opts,"filename" ), (flags &BDRV_O_RDWR ) ?O_RDWR :O_RDONLY , errp);if (ret <0 ) { -return ret; + goto out; } bs->total_sectors = ret; + ret =0 ; +out: +qemu_opts_del (opts);return 0 ; }
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v2 1/3] nfs: Fix leak of opts in nfs_file_open
Quoted 20 lines · Fam Zheng
Signed-off-by Fam Zheng <[email protected]>--- block/nfs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)block/nfs.c +2
-1@@ -393,15 +393,19 @@ static int nfs_file_open(BlockDriverState *bs, QDict *options, int flags,qemu_opts_absorb_qdict (opts, options, &local_err);if (local_err) {error_propagate (errp, local_err); -return -EINVAL ; + ret = -EINVAL ; + goto out; } ret =nfs_client_open (client,qemu_opt_get (opts,"filename" ), (flags &BDRV_O_RDWR ) ?O_RDWR :O_RDONLY , errp);
block/nfs.c static int nfs_file_open(BlockDriverState *bs, QDict *options, int flags, · line 410
Quoted 10 lines
block/nfs.c +4
-1if (ret <0 ) { -return ret; + goto out; } bs->total_sectors = ret; + ret =0 ; +out: +qemu_opts_del (opts);return 0 ;
Hmm ... "return ret;" ? ;)
Quoted 5 lines
block/nfs.c +0
-0}Signature · 2 lines
-- 2.1.0
Re: [Qemu-devel] [PATCH v2 1/3] nfs: Fix leak of opts in nfs_file_open
Quoted 30 lines · Benoît Canet
Quoted 28 lines · Fam Zheng
Signed-off-by Fam Zheng <[email protected]>--- block/nfs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)block/nfs.c +6
-2@@ -393,15 +393,19 @@ static int nfs_file_open(BlockDriverState *bs, QDict *options, int flags,qemu_opts_absorb_qdict (opts, options, &local_err);if (local_err) {error_propagate (errp, local_err); -return -EINVAL ; + ret = -EINVAL ; + goto out; } ret =nfs_client_open (client,qemu_opt_get (opts,"filename" ), (flags &BDRV_O_RDWR ) ?O_RDWR :O_RDONLY , errp);if (ret <0 ) { -return ret; + goto out; } bs->total_sectors = ret; + ret =0 ; +out: +qemu_opts_del (opts);
Quoted 4 lines
block/nfs.c static int nfs_file_open(BlockDriverState *bs, QDict *options, int flags, · line 409
Quoted 1 line
block/nfs.c +0
-0return 0 ;Hmm ... "return ret;" ? ;)
Oops, patches that are not right in the first try always tend to fail again :)
Fam
PATCH v2 2/3 blkverify: Fix leak of opts in blkverify_open
In reply to Fam Zheng--- block/blkverify.c | 1 + 1 file changed, 1 insertion(+)
block/blkverify.c +1 -0
@@ -158,6 +158,7 @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags, ret =0 ; fail: +qemu_opts_del (opts);return ret; }
Signature · 1 line
2.1.0
PATCH v2 3/3 quorum: Fix leak of opts in quorum_open
In reply to Fam Zheng--- block/quorum.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
block/quorum.c +2 -1
@@ -796,7 +796,7 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags, {BDRVQuorumState *s = bs->opaque;Error *local_err =NULL ; -QemuOpts *opts; +QemuOpts *opts =NULL ;bool *opened;QDict *sub =NULL ;QList *list =NULL ;
@@ -908,6 +908,7 @@ close_exit:g_free (s->bs);g_free (opened); exit: +qemu_opts_del (opts);/* propagate error */ if (local_err) {error_propagate (errp, local_err);
Signature · 1 line
2.1.0