hw/arm/virt: free flash devices and OEM strings on finalization
Flash devices created in instance_init via qdev_new() hold an extra reference that is only dropped on sysbus_realize_and_unref(). When the machine is destroyed before realization, the flash objects leak. Also, the oem_id and oem_table_id strings from g_strndup() are never freed. Fixes: 602b458201ff ("acpi: Permit OEM ID and OEM table ID fields to be changed") Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Marc-André Lureau committed
Apr 27, 2026 at 16:10 UTC
60280b9ccdc60d448dd20af79d846c8278d8fd5e
1 file changed
+14
hw/arm/virt.c
+14
@@ -4321,6 +4321,19 @@ static void virt_instance_init(Object *obj)
4321
cxl_machine_init(obj, &vms->cxl_devices_state);
4322
}
4323
4324
+static void virt_instance_finalize(Object *obj)
4325
+{
4326
+ VirtMachineState *vms = VIRT_MACHINE(obj);
4327
+
4328
+ for (int i = 0; i < ARRAY_SIZE(vms->flash); i++) {
4329
+ if (vms->flash[i] && !qdev_is_realized(DEVICE(vms->flash[i]))) {
4330
+ object_unref(OBJECT(vms->flash[i]));
4331
+ }
4332
+ }
4333
+ g_free(vms->oem_id);
4334
+ g_free(vms->oem_table_id);
4335
+}
4336
+
4337
static const TypeInfo virt_machine_info = {
4338
.name = TYPE_VIRT_MACHINE,
4339
.parent = TYPE_MACHINE,
@@ -4329,6 +4342,7 @@ static const TypeInfo virt_machine_info = {
4342
.class_size = sizeof(VirtMachineClass),
4343
.class_init = virt_machine_class_init,
4344
.instance_init = virt_instance_init,
4345
+ .instance_finalize = virt_instance_finalize,
4346
.interfaces = (const InterfaceInfo[]) {
4347
{ TYPE_HOTPLUG_HANDLER },
4348
{ }