Skip to contentSkip to conversation

block: Fix leaks of opts in block drivers

PATCH Applied Fam Zheng 3 participants 6 messages Aug 28, 2014 – Aug 29, 2014 Block layer

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

v3 cover block: Fix leaks of opts in block drivers

Remember to call qemu_opts_del before function returning.

v3: Fix nfs return code again! (Benoit)

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       | 10 +++++++---
 block/quorum.c    |  3 ++-
 3 files changed, 10 insertions(+), 4 deletions(-)
Signature · 1 line
2.1.0
author
#1 lore raw

PATCH v3 1/3 nfs: Fix leak of opts in nfs_file_open

---
 block/nfs.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
block/nfs.c +7 -3
index 93d87f3..194f301 100644
@@ -393,16 +393,20 @@ 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;
-    return 0;
+    ret = 0;
+out:
+    qemu_opts_del(opts);
+    return ret;
 }
 
 static int nfs_file_create(const char *url, QemuOpts *opts, Error **errp)
Signature · 1 line
2.1.0
Reviewed-by on v3 1/3
#2 lore raw

Re: [Qemu-devel] [PATCH v3 1/3] nfs: Fix leak of opts in nfs_file_open

Quoted 37 lines · Fam Zheng
---
 block/nfs.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
block/nfs.c +7 -3
index 93d87f3..194f301 100644
@@ -393,16 +393,20 @@ 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;
-    return 0;
+    ret = 0;
+out:
+    qemu_opts_del(opts);
+    return ret;
 }
 
 static int nfs_file_create(const char *url, QemuOpts *opts, Error **errp)
Signature · 1 line
2.1.0
author
#3 lore raw

PATCH v3 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
index 7c78ca4..163064c 100644
@@ -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
author
#4 lore raw

PATCH v3 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
index 0de07bb..ffe8bd9 100644
@@ -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
#5 lore raw
In reply to Fam Zheng
Quoted 15 lines · Fam Zheng

Remember to call qemu_opts_del before function returning.

v3: Fix nfs return code again! (Benoit)

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

Quoted 9 lines
 block/blkverify.c |  1 +
 block/nfs.c       | 10 +++++++---
 block/quorum.c    |  3 ++-
 3 files changed, 10 insertions(+), 4 deletions(-)
Signature · 1 line
2.1.0

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan