Pan Nengyuan <pannengy...@huawei.com> writes: > In qmp_object_add(), user_creatable_add_type() may set errp with some error > message and > return NULL. In this case, qmp_object_add() still alloc memory to *ret_data > which return > to the caller and causes a memory leak. > > This patch do this alloc() action only if obj is not NULL to fix it. And > initialize ret_data > in xen-block to avoid a possible uninitialized error. > > The Leak stack: > Direct leak of 4120 byte(s) in 1 object(s) allocated from: > #0 0x7f6106ce5970 in __interceptor_calloc (/lib64/libasan.so.5+0xef970) > #1 0x7f6105e6a49d in g_malloc0 (/lib64/libglib-2.0.so.0+0x5249d) > #2 0x55d2c58c17fd in qdict_new > /mnt/sdb/qemu-new/qemu_test/qemu/qobject/qdict.c:29 > #3 0x55d2c53a0051 in qmp_object_add > /mnt/sdb/qemu-new/qemu_test/qemu/qom/qom-qmp-cmds.c:291 > #4 0x55d2c57b47da in do_qmp_dispatch > /mnt/sdb/qemu-new/qemu_test/qemu/qapi/qmp-dispatch.c:132 > #5 0x55d2c57b47da in qmp_dispatch > /mnt/sdb/qemu-new/qemu_test/qemu/qapi/qmp-dispatch.c:175 > #6 0x55d2c52f1430 in monitor_qmp_dispatch > /mnt/sdb/qemu-new/qemu_test/qemu/monitor/qmp.c:145 > #7 0x55d2c52f3087 in monitor_qmp_bh_dispatcher > /mnt/sdb/qemu-new/qemu_test/qemu/monitor/qmp.c:234 > #8 0x55d2c58e6153 in aio_bh_call > /mnt/sdb/qemu-new/qemu_test/qemu/util/async.c:136 > > Fixes: 5f07c4d60d091320186e7b0edaf9ed2cc16b2d1e > Reported-by: Euler Robot <euler.ro...@huawei.com> > Signed-off-by: Pan Nengyuan <pannengy...@huawei.com>
Reviewed-by: Markus Armbruster <arm...@redhat.com>