system/ioport: Fix qom-list-properties crash on portio list obj
Currently qom-list-properties QMP command will crash when querying the portio list MR object. It's because its finalize() assumes full initialization done in portio_list_add_1(). Provide a simple fix for now to avoid the crash. There is chance for a longer term fix, ideally MR should be initialized in instance_init(). However that'll need more work, and that should also be done with cleaning the hard-coded MR operations in portio_list_add_1(). To be explored. Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> Link: https://lore.kernel.org/r/87a4uvw066.fsf@pond.sub.org Reported-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Peter Xu <peterx@redhat.com>
Peter Xu committed
Apr 23, 2026 at 14:32 UTC
010a30d8a48355333401a97288aef2a79f2d3cb6
1 file changed
+9
-2
system/ioport.c
+9
-2
@@ -346,8 +346,15 @@ static void memory_region_portio_list_finalize(Object *obj)
346
{
347
MemoryRegionPortioList *mrpio = MEMORY_REGION_PORTIO_LIST(obj);
348
349
- object_unref(&mrpio->mr);
350
- g_free(mrpio->ports);
349
+ /*
350
+ * This check makes sure any random object_new() (without doing the
351
+ * rest inits in portio_list_add_1()) will not crash when finalizing.
352
+ * One example is QMP command qom-list-properties.
353
+ */
354
+ if (mrpio->ports) {
355
+ object_unref(&mrpio->mr);
356
+ g_free(mrpio->ports);
357
+ }
358
}
359
360
static const TypeInfo memory_region_portio_list_info = {