From fde4dbb7e61396a38fcc172ab02dbf839b468ebe Mon Sep 17 00:00:00 2001 From: Zhenzhong Duan Date: Mon, 9 Oct 2023 10:20:46 +0800 Subject: vfio/pci: Fix a potential memory leak in vfio_listener_region_add MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When there is an failure in vfio_listener_region_add() and the section belongs to a ram device, there is an inaccurate error report which should never be related to vfio_dma_map failure. The memory holding err is also incrementally leaked in each failure. Fix it by reporting the real error and free it. Fixes: 567b5b309ab ("vfio/pci: Relax DMA map errors for MMIO regions") Signed-off-by: Zhenzhong Duan Signed-off-by: Cédric Le Goater --- hw/vfio/common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'hw') diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 9e61de03ee..5ff5acf1d8 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -763,7 +763,7 @@ static void vfio_listener_region_add(MemoryListener *listener, fail: if (memory_region_is_ram_device(section->mr)) { - error_report("failed to vfio_dma_map. pci p2p may not work"); + error_reportf_err(err, "PCI p2p may not work: "); return; } /* -- cgit v1.2.3