summary refs log tree commit diff stats
path: root/hw/core
diff options
context:
space:
mode:
authorGao Shiyuan <gaoshiyuan@baidu.com>2024-08-29 21:10:05 +0800
committerPeter Maydell <peter.maydell@linaro.org>2024-09-05 13:12:37 +0100
commit99ec7b440a1d6a6ef07450b68687d24d13a25fb5 (patch)
tree7cfb2e134e50e9402a35887e2def92fcdcdefc83 /hw/core
parent17e93dd5faaf3ba8a1df099cc9396e4943baa892 (diff)
downloadfocaccia-qemu-99ec7b440a1d6a6ef07450b68687d24d13a25fb5.tar.gz
focaccia-qemu-99ec7b440a1d6a6ef07450b68687d24d13a25fb5.zip
platform-bus: fix refcount leak
memory_region_find() returns an MR which it is the caller's
responsibility to unref, but platform_bus_map_mmio() was
forgetting to do so, thus leaking the MR.

Signed-off-by: Gao Shiyuan <gaoshiyuan@baidu.com>
Message-id: 20240829131005.9196-1-gaoshiyuan@baidu.com
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
[PMM: tweaked commit message]
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw/core')
-rw-r--r--hw/core/platform-bus.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/hw/core/platform-bus.c b/hw/core/platform-bus.c
index b8487b26b6..dc58bf505a 100644
--- a/hw/core/platform-bus.c
+++ b/hw/core/platform-bus.c
@@ -145,9 +145,12 @@ static void platform_bus_map_mmio(PlatformBusDevice *pbus, SysBusDevice *sbdev,
      * the target device's memory region
      */
     for (off = 0; off < pbus->mmio_size; off += alignment) {
-        if (!memory_region_find(&pbus->mmio, off, size).mr) {
+        MemoryRegion *mr = memory_region_find(&pbus->mmio, off, size).mr;
+        if (!mr) {
             found_region = true;
             break;
+        } else {
+            memory_region_unref(mr);
         }
     }