]> www.infradead.org Git - users/dwmw2/qemu.git/commitdiff
platform-bus: fix refcount leak
authorGao Shiyuan <gaoshiyuan@baidu.com>
Thu, 29 Aug 2024 13:10:05 +0000 (21:10 +0800)
committerPeter Maydell <peter.maydell@linaro.org>
Thu, 5 Sep 2024 12:12:37 +0000 (13:12 +0100)
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>
hw/core/platform-bus.c

index b8487b26b674e46e445749118abc7b2cc6918f0f..dc58bf505aa2f5c0460eed9b41d9ee41d92b28f1 100644 (file)
@@ -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);
         }
     }