fix two memory leaks in object_create()
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
PATCH 1/2 vl: free err
err is not freed after use, thus causing memory leak. This patch fixes it.
Signed-off-by Hu Tao <[email protected]>
--- vl.c | 1 + 1 file changed, 1 insertion(+)
vl.c +1 -0
@@ -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
Michael Tokarev
AppliedRe: [Qemu-devel] [Qemu-trivial] [PATCH 1/2] vl: free err
Applied to trivial, thank you!
/mjt
PATCH 2/2 vl: call visit_end_struct() in the error path
In reply to Hu TaoIn the error path we should also call visit_end_struct(), otherwise we will have memory leak.
Signed-off-by Hu Tao <[email protected]>
--- vl.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
vl.c +7 -6
@@ -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