object-add: don't create return value if failed
authorPaolo Bonzini <pbonzini@redhat.com>
Thu, 26 Mar 2020 09:41:21 +0000 (10:41 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 2 Apr 2020 18:56:10 +0000 (14:56 -0400)
No need to return an empty value from object-add (it would also leak
if the command failed).  While at it, remove the "if" around object_unref
since object_unref handles NULL arguments just fine.

Reported-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20200325184723.2029630-4-marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qom/qom-qmp-cmds.c

index 435193b03656366223e34d558e890a855002eda6..e47ebe8ed1236599740f938c5809dda086f54537 100644 (file)
@@ -285,10 +285,7 @@ void qmp_object_add(QDict *qdict, QObject **ret_data, Error **errp)
     v = qobject_input_visitor_new(QOBJECT(qdict));
     obj = user_creatable_add_type(type, id, qdict, v, errp);
     visit_free(v);
-    if (obj) {
-        object_unref(obj);
-    }
-    *ret_data = QOBJECT(qdict_new());
+    object_unref(obj);
 }
 
 void qmp_object_del(const char *id, Error **errp)