qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] qom-qmp-cmds: Fix another memory leak in qmp_object_add()


From: Markus Armbruster
Subject: [PATCH] qom-qmp-cmds: Fix another memory leak in qmp_object_add()
Date: Tue, 17 Mar 2020 10:22:41 +0100

When user_creatable_add_type() fails, qmp_object_add() returns both
its error and the usual empty QDict success value.  The QMP core
handles the error, and ignores the success value, leaking it.  Exposed
by qmp-cmd-test case /x86_64/qmp/object-add-without-props, and duly
reported both by ASan and valgrind.

To plug the leak, set the success value only on success.

Fixes: 5f07c4d60d091320186e7b0edaf9ed2cc16b2d1e
Cc: Kevin Wolf <address@hidden>
Signed-off-by: Markus Armbruster <address@hidden>
---
 qom/qom-qmp-cmds.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qom/qom-qmp-cmds.c b/qom/qom-qmp-cmds.c
index 435193b036..6bd137ccbf 100644
--- a/qom/qom-qmp-cmds.c
+++ b/qom/qom-qmp-cmds.c
@@ -287,8 +287,8 @@ void qmp_object_add(QDict *qdict, QObject **ret_data, Error 
**errp)
     visit_free(v);
     if (obj) {
         object_unref(obj);
+        *ret_data = QOBJECT(qdict_new());
     }
-    *ret_data = QOBJECT(qdict_new());
 }
 
 void qmp_object_del(const char *id, Error **errp)
-- 
2.21.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]