nubus: fix memory leak in nubus_bridge_init()
PATCH 1/1 nubus: fix memory leak in nubus_bridge_init()
Move qbus_init() to a realize function.
Leak detected by valgrind:
QTEST_QEMU_BINARY="valgrind --leak-check=full \ --show-leak-kinds=definite ./qemu-system-m68k" \ tests/qtest/device-introspect-test \ -p /m68k/device/introspect/concrete/defaults/none ... ==606164== 6 bytes in 1 blocks are definitely lost in loss record 123 of 1,771 ==606164== at 0x484486F: malloc (vg_replace_malloc.c:381) ==606164== by 0x4FF0428: g_malloc (gmem.c:106) ==606164== by 0x5004433: g_strdup (gstrfuncs.c:364) ==606164== by 0x3D1BA6: memory_region_do_init (memory.c:1170) ==606164== by 0x3D1BA6: memory_region_init (memory.c:1195) ==606164== by 0x375C88: nubus_init (nubus-bus.c:104) ==606164== by 0x49DE82: object_init_with_type (object.c:377) ==606164== by 0x49DE82: object_initialize_with_type (object.c:519) ==606164== by 0x495772: qbus_init (bus.c:158) ==606164== by 0x375DDB: nubus_bridge_init (nubus-bridge.c:21) ==606164== by 0x49DE82: object_init_with_type (object.c:377) ==606164== by 0x49DE82: object_initialize_with_type (object.c:519) ==606164== by 0x49E028: object_new_with_type (object.c:734) ==606164== by 0x5660AC: qmp_device_list_properties (qom-qmp-cmds.c:146) ==606164== by 0x67CC35: qmp_marshal_device_list_properties (qapi-commands-qdev.c:66) ...
Reported-by Thomas Huth <[email protected]>
Signed-off-by Laurent Vivier <[email protected]>
--- hw/nubus/nubus-bridge.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
hw/nubus/nubus-bridge.c +9 -2
@@ -18,11 +18,17 @@ static void nubus_bridge_init(Object *obj)NubusBridge *s =NUBUS_BRIDGE (obj);NubusBus *bus = &s->bus; -qbus_init (bus,sizeof (s->bus),TYPE_NUBUS_BUS ,DEVICE (s),NULL ); -qdev_init_gpio_out (DEVICE (s), bus->irqs,NUBUS_IRQS ); } +static void nubus_bridge_realize (DeviceState *d,Error **errp) +{ +NubusBridge *s =NUBUS_BRIDGE (d); +NubusBus *bus = &s->bus; + +qbus_init (bus,sizeof (NubusBus),TYPE_NUBUS_BUS , d,NULL ); +} +static Property nubus_bridge_properties[] = {DEFINE_PROP_UINT16 ("slot-available-mask" , NubusBridge, bus.slot_available_mask,0xffff ),
@@ -34,6 +40,7 @@ static void nubus_bridge_class_init(ObjectClass *klass, void *data)DeviceClass *dc =DEVICE_CLASS (klass); dc->fw_name ="nubus" ; + dc->realize = nubus_bridge_realize;device_class_set_props (dc, nubus_bridge_properties); }
Signature · 1 line
2.35.1
Quoted 58 lines · Laurent Vivier
Move
qbus_init()to a realize function.Leak detected by valgrind:
QTEST_QEMU_BINARY="valgrind --leak-check=full \ --show-leak-kinds=definite ./qemu-system-m68k" \ tests/qtest/device-introspect-test \ -p /m68k/device/introspect/concrete/defaults/none ... ==606164== 6 bytes in 1 blocks are definitely lost in loss record 123 of 1,771 ==606164== at 0x484486F: malloc (vg_replace_malloc.c:381) ==606164== by 0x4FF0428: g_malloc (gmem.c:106) ==606164== by 0x5004433: g_strdup (gstrfuncs.c:364) ==606164== by 0x3D1BA6: memory_region_do_init (memory.c:1170) ==606164== by 0x3D1BA6: memory_region_init (memory.c:1195) ==606164== by 0x375C88: nubus_init (nubus-bus.c:104) ==606164== by 0x49DE82: object_init_with_type (object.c:377) ==606164== by 0x49DE82: object_initialize_with_type (object.c:519) ==606164== by 0x495772: qbus_init (bus.c:158) ==606164== by 0x375DDB: nubus_bridge_init (nubus-bridge.c:21) ==606164== by 0x49DE82: object_init_with_type (object.c:377) ==606164== by 0x49DE82: object_initialize_with_type (object.c:519) ==606164== by 0x49E028: object_new_with_type (object.c:734) ==606164== by 0x5660AC: qmp_device_list_properties (qom-qmp-cmds.c:146) ==606164== by 0x67CC35: qmp_marshal_device_list_properties (qapi-commands-qdev.c:66) ...Reported-by Thomas Huth <[email protected]>Signed-off-by Laurent Vivier <[email protected]>--- hw/nubus/nubus-bridge.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)hw/nubus/nubus-bridge.c +8
-2@@ -18,11 +18,17 @@ static void nubus_bridge_init(Object *obj)NubusBridge *s =NUBUS_BRIDGE (obj);NubusBus *bus = &s->bus; -qbus_init (bus,sizeof (s->bus),TYPE_NUBUS_BUS ,DEVICE (s),NULL ); -qdev_init_gpio_out (DEVICE (s), bus->irqs,NUBUS_IRQS ); } +static void nubus_bridge_realize (DeviceState *d,Error **errp) +{ +NubusBridge *s =NUBUS_BRIDGE (d); +NubusBus *bus = &s->bus; + +qbus_init (bus,sizeof (NubusBus),TYPE_NUBUS_BUS , d,NULL ); +} +static Property nubus_bridge_properties[] = {DEFINE_PROP_UINT16 ("slot-available-mask" , NubusBridge, bus.slot_available_mask,0xffff ),
hw/nubus/nubus-bridge.c static void nubus_bridge_class_init(ObjectClass *klass, void *data) · line 45
Quoted 6 lines
hw/nubus/nubus-bridge.c +1
-0@@ -34,6 +40,7 @@ static void nubus_bridge_class_init(ObjectClass *klass, void *data)DeviceClass *dc =DEVICE_CLASS (klass); dc->fw_name ="nubus" ; + dc->realize = nubus_bridge_realize;device_class_set_props (dc, nubus_bridge_properties); }
Since qbus_init() is adding a bus that can have child devices, I think the correct solution here would be to add an instance_finalize function to the Nubus bridge device that calls qbus_finalize().
ATB,
Mark.