hw/i386/pc: free pcspk on finalization
Add pc_machine_finalize() to unref the pcspk device when it was never realized. Once realized, the bus owns it and no action is needed. Fixes: 6b8d1416482f ("audio: create pcspk device early") Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Marc-André Lureau committed
Apr 27, 2026 at 15:00 UTC
0d6ee5945044d30f66553bb62457fd7b60596e46
1 file changed
+10
hw/i386/pc.c
+10
@@ -1610,6 +1610,15 @@ static void pc_machine_initfn(Object *obj)
1610
}
1611
}
1612
1613
+static void pc_machine_finalize(Object *obj)
1614
+{
1615
+ PCMachineState *pcms = PC_MACHINE(obj);
1616
+
1617
+ if (pcms->pcspk && !qdev_is_realized(DEVICE(pcms->pcspk))) {
1618
+ object_unref(OBJECT(pcms->pcspk));
1619
+ }
1620
+}
1621
+
1622
static void pc_machine_reset(MachineState *machine, ResetType type)
1623
{
1624
CPUState *cs;
@@ -1748,6 +1757,7 @@ static const TypeInfo pc_machine_info = {
1757
.abstract = true,
1758
.instance_size = sizeof(PCMachineState),
1759
.instance_init = pc_machine_initfn,
1760
+ .instance_finalize = pc_machine_finalize,
1761
.class_size = sizeof(PCMachineClass),
1762
.class_init = pc_machine_class_init,
1763
.interfaces = (const InterfaceInfo[]) {