Skip to content

Commit 9b6abdc

Browse files
panny060kevmw
authored andcommitted
qom-qmp-cmds: fix two memleaks in qmp_object_add
'type/id' forgot to free in qmp_object_add, this patch fix that. The leak stack: Direct leak of 84 byte(s) in 6 object(s) allocated from: #0 0x7fe2a5ebf768 in __interceptor_malloc (/lib64/libasan.so.5+0xef768) qemu#1 0x7fe2a5044445 in g_malloc (/lib64/libglib-2.0.so.0+0x52445) qemu#2 0x7fe2a505dd92 in g_strdup (/lib64/libglib-2.0.so.0+0x6bd92) qemu#3 0x56344954e692 in qmp_object_add /mnt/sdb/qemu-new/qemu_test/qemu/qom/qom-qmp-cmds.c:258 qemu#4 0x563449960f5a in do_qmp_dispatch /mnt/sdb/qemu-new/qemu_test/qemu/qapi/qmp-dispatch.c:132 qemu#5 0x563449960f5a in qmp_dispatch /mnt/sdb/qemu-new/qemu_test/qemu/qapi/qmp-dispatch.c:175 qemu#6 0x563449498a30 in monitor_qmp_dispatch /mnt/sdb/qemu-new/qemu_test/qemu/monitor/qmp.c:145 qemu#7 0x56344949a64f in monitor_qmp_bh_dispatcher /mnt/sdb/qemu-new/qemu_test/qemu/monitor/qmp.c:234 qemu#8 0x563449a92a3a in aio_bh_call /mnt/sdb/qemu-new/qemu_test/qemu/util/async.c:136 Direct leak of 54 byte(s) in 6 object(s) allocated from: #0 0x7fe2a5ebf768 in __interceptor_malloc (/lib64/libasan.so.5+0xef768) qemu#1 0x7fe2a5044445 in g_malloc (/lib64/libglib-2.0.so.0+0x52445) qemu#2 0x7fe2a505dd92 in g_strdup (/lib64/libglib-2.0.so.0+0x6bd92) qemu#3 0x56344954e6c4 in qmp_object_add /mnt/sdb/qemu-new/qemu_test/qemu/qom/qom-qmp-cmds.c:267 qemu#4 0x563449960f5a in do_qmp_dispatch /mnt/sdb/qemu-new/qemu_test/qemu/qapi/qmp-dispatch.c:132 qemu#5 0x563449960f5a in qmp_dispatch /mnt/sdb/qemu-new/qemu_test/qemu/qapi/qmp-dispatch.c:175 qemu#6 0x563449498a30 in monitor_qmp_dispatch /mnt/sdb/qemu-new/qemu_test/qemu/monitor/qmp.c:145 qemu#7 0x56344949a64f in monitor_qmp_bh_dispatcher /mnt/sdb/qemu-new/qemu_test/qemu/monitor/qmp.c:234 qemu#8 0x563449a92a3a in aio_bh_call /mnt/sdb/qemu-new/qemu_test/qemu/util/async.c:136 Fixes: 5f07c4d Reported-by: Euler Robot <euler.robot@huawei.com> Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com> Message-Id: <20200310064640.5059-1-pannengyuan@huawei.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Acked-by: Igor Mammedov <imammedo@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
1 parent ba29883 commit 9b6abdc

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

qom/qom-qmp-cmds.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -247,26 +247,22 @@ void qmp_object_add(QDict *qdict, QObject **ret_data, Error **errp)
247247
QDict *pdict;
248248
Visitor *v;
249249
Object *obj;
250-
const char *type;
251-
const char *id;
250+
g_autofree char *type = NULL;
251+
g_autofree char *id = NULL;
252252

253-
type = qdict_get_try_str(qdict, "qom-type");
253+
type = g_strdup(qdict_get_try_str(qdict, "qom-type"));
254254
if (!type) {
255255
error_setg(errp, QERR_MISSING_PARAMETER, "qom-type");
256256
return;
257-
} else {
258-
type = g_strdup(type);
259-
qdict_del(qdict, "qom-type");
260257
}
258+
qdict_del(qdict, "qom-type");
261259

262-
id = qdict_get_try_str(qdict, "id");
260+
id = g_strdup(qdict_get_try_str(qdict, "id"));
263261
if (!id) {
264262
error_setg(errp, QERR_MISSING_PARAMETER, "id");
265263
return;
266-
} else {
267-
id = g_strdup(id);
268-
qdict_del(qdict, "id");
269264
}
265+
qdict_del(qdict, "id");
270266

271267
props = qdict_get(qdict, "props");
272268
if (props) {

0 commit comments

Comments
 (0)