qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] hw: Fix qemu_init_irq() leaks
@ 2025-08-21 15:40 Peter Maydell
  2025-08-21 15:40 ` [PATCH 1/3] hw/irq: New qemu_init_irq_child() function Peter Maydell
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Peter Maydell @ 2025-08-21 15:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: Michael S. Tsirkin, Paolo Bonzini, Philippe Mathieu-Daudé

The qemu_init_irq() method initializes an IRQ object, but
the caller is responsible for eventually freeing it by calling
qemu_free_irq(). Generally we don't remember to do this.

Implement a harder-to-misuse API, qemu_init_irq_child().  This is to
qemu_init_irq() what object_initialize_child() is to
object_initialize(): it both initializes the object and makes it a
child of the parent QOM object.  If you use this in a device's
realize or instance_init method then the IRQ will be automatically
freed when the device is destroyed.

Patch 1 is the new function; patches 2 and 3 are bugfixes for
leaks that show up with ASAN in device-introspect-test (which
does an instance_init -> deinit on every device).

The other callers of qemu_init_irq() could also be changed over
to use this new function, but they don't cause in-practice
leaks because they call the function in realize, and they
are devices which are never unrealized.

thanks
-- PMM

Peter Maydell (3):
  hw/irq: New qemu_init_irq_child() function
  hw/char/serial-pci-multi: Use qemu_init_irq_child() to avoid leak
  hw/ide/ich.c: Use qemu_init_irq_child() to avoid memory leak

 include/hw/irq.h           | 23 ++++++++++++++++++++++-
 hw/char/serial-pci-multi.c |  4 +++-
 hw/core/irq.c              |  8 ++++++++
 hw/ide/ich.c               |  3 ++-
 4 files changed, 35 insertions(+), 3 deletions(-)

-- 
2.43.0



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-09-02 10:51 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-21 15:40 [PATCH 0/3] hw: Fix qemu_init_irq() leaks Peter Maydell
2025-08-21 15:40 ` [PATCH 1/3] hw/irq: New qemu_init_irq_child() function Peter Maydell
2025-09-02 10:21   ` Philippe Mathieu-Daudé
2025-08-21 15:40 ` [PATCH 2/3] hw/char/serial-pci-multi: Use qemu_init_irq_child() to avoid leak Peter Maydell
2025-09-02 10:23   ` Philippe Mathieu-Daudé
2025-09-02 10:50     ` Peter Maydell
2025-08-21 15:40 ` [PATCH 3/3] hw/ide/ich.c: Use qemu_init_irq_child() to avoid memory leak Peter Maydell
2025-09-02 10:24   ` Philippe Mathieu-Daudé
2025-09-02 10:29 ` [PATCH 0/3] hw: Fix qemu_init_irq() leaks Philippe Mathieu-Daudé

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).