Skip to contentSkip to conversation

fix two memory leaks in object_create()

PATCH Applied Hu Tao 2 participants 4 messages Aug 15, 2014

lore
Share & tools
lore

Hu Tao

author
#0 lore raw

cover fix two memory leaks in object_create()

See each patch for the details.

Hu Tao (2):
vl: free err
vl: call visit_end_struct() in the error path

 vl.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
Signature · 1 line
1.9.3
author
#1 lore raw

PATCH 1/2 vl: free err

err is not freed after use, thus causing memory leak. This patch fixes it.

---
 vl.c | 1 +
 1 file changed, 1 insertion(+)
vl.c +1 -0
index a8029d5..6011aff 100644
@@ -2917,6 +2917,7 @@ out:
     g_free(dummy);
     if (err) {
         qerror_report_err(err);
+        error_free(err);
         return -1;
     }
     return 0;
Signature · 1 line
1.9.3
#2 lore raw

Re: [Qemu-devel] [Qemu-trivial] [PATCH 1/2] vl: free err

Applied to trivial, thank you!

/mjt

author
#3 lore raw

PATCH 2/2 vl: call visit_end_struct() in the error path

In reply to Hu Tao

In the error path we should also call visit_end_struct(), otherwise we will have memory leak.

---
 vl.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
vl.c +7 -6
index 6011aff..738ef45 100644
@@ -2876,6 +2876,7 @@ static int object_create(QemuOpts *opts, void *opaque)
     char *type = NULL;
     char *id = NULL;
     void *dummy = NULL;
+    bool del_id_on_error = false;
     OptsVisitor *ov;
     QDict *pdict;
 
@@ -2890,21 +2891,21 @@ static int object_create(QemuOpts *opts, void *opaque)
     qdict_del(pdict, "qom-type");
     visit_type_str(opts_get_visitor(ov), &type, "qom-type", &err);
     if (err) {
-        goto out;
+        goto out_struct;
     }
 
     qdict_del(pdict, "id");
     visit_type_str(opts_get_visitor(ov), &id, "id", &err);
     if (err) {
-        goto out;
+        goto out_struct;
     }
 
     object_add(type, id, pdict, opts_get_visitor(ov), &err);
-    if (err) {
-        goto out;
-    }
+    del_id_on_error = true;
+
+out_struct:
     visit_end_struct(opts_get_visitor(ov), &err);
-    if (err) {
+    if (err && del_id_on_error) {
         qmp_object_del(id, NULL);
     }
 
Signature · 1 line
1.9.3