Skip to contentSkip to conversation

sheepdog: Fix sd_co_create_opts() memory leaks

PATCH In review Kevin Wolf 2 participants 2 messages May 3, 2018 Block layer

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

PATCH 1/1 sheepdog: Fix sd_co_create_opts() memory leaks

Both the option string for the 'redundancy' option and the SheepdogRedundancy object that is created accordingly could be leaked in error paths. This fixes the memory leaks.

Reported by Coverity (CID 1390614 and 1390641).

---
 block/sheepdog.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
block/sheepdog.c +3 -1
index a2f26efc0e..6ec647e558 100644
@@ -1987,6 +1987,7 @@ static SheepdogRedundancy *parse_redundancy_str(const char *opt)
     } else {
         ret = qemu_strtol(n2, NULL, 10, &parity);
         if (ret < 0) {
+            g_free(redundancy);
             return NULL;
         }
 
@@ -2183,7 +2184,7 @@ static int coroutine_fn sd_co_create_opts(const char *filename, QemuOpts *opts,
     QDict *qdict, *location_qdict;
     QObject *crumpled;
     Visitor *v;
-    const char *redundancy;
+    char *redundancy;
     Error *local_err = NULL;
     int ret;
 
@@ -2253,6 +2254,7 @@ static int coroutine_fn sd_co_create_opts(const char *filename, QemuOpts *opts,
 fail:
     qapi_free_BlockdevCreateOptions(create_options);
     QDECREF(qdict);
+    g_free(redundancy);
     return ret;
 }
 
Signature · 1 line
2.13.6
#1 lore raw
Quoted 44 lines · Kevin Wolf

Both the option string for the 'redundancy' option and the SheepdogRedundancy object that is created accordingly could be leaked in error paths. This fixes the memory leaks.

Reported by Coverity (CID 1390614 and 1390641).

---
 block/sheepdog.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
block/sheepdog.c +3 -1
index a2f26efc0e..6ec647e558 100644
@@ -1987,6 +1987,7 @@ static SheepdogRedundancy *parse_redundancy_str(const char *opt)
     } else {
         ret = qemu_strtol(n2, NULL, 10, &parity);
         if (ret < 0) {
+            g_free(redundancy);
             return NULL;
         }
 
@@ -2183,7 +2184,7 @@ static int coroutine_fn sd_co_create_opts(const char *filename, QemuOpts *opts,
     QDict *qdict, *location_qdict;
     QObject *crumpled;
     Visitor *v;
-    const char *redundancy;
+    char *redundancy;
     Error *local_err = NULL;
     int ret;
 
@@ -2253,6 +2254,7 @@ static int coroutine_fn sd_co_create_opts(const char *filename, QemuOpts *opts,
 fail:
     qapi_free_BlockdevCreateOptions(create_options);
     QDECREF(qdict);
+    g_free(redundancy);
     return ret;
 }
 
Signature · 1 line
2.13.6

Thanks,

Reviewed & applied to my block branch:

git://github.com/codyprime/qemu-kvm-jtc block

-Jeff