@@ -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);
}
In the error path we should also call visit_end_struct(), otherwise we will have memory leak. Signed-off-by: Hu Tao <hutao@cn.fujitsu.com> --- vl.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)