Skip to contentSkip to conversation

spapr_pci: fix leak in spapr_phb_vfio_get_loc_code

PATCH New Paolo Bonzini 1 participant 1 message Sep 5, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spapr_pci: fix leak in spapr_phb_vfio_get_loc_code

Overwriting "path" in the second call to g_strdup_printf() causes a memory leak, even if the variable itself is g_autofree.

Reported by Coverity as CID 1460454.

---
 hw/ppc/spapr_pci.c | 1 +
 1 file changed, 1 insertion(+)
hw/ppc/spapr_pci.c +1 -0
index 67e9d468aa..57c8a4f085 100644
@@ -800,6 +800,7 @@ static char *spapr_phb_vfio_get_loc_code(SpaprPhbState *sphb,  PCIDevice *pdev)
     }
 
     /* Construct and read from host device tree the loc-code */
+    g_free(path);
     path = g_strdup_printf("/proc/device-tree%s/ibm,loc-code", devspec);
     if (!g_file_get_contents(path, &buf, NULL, NULL)) {
         return NULL;
Signature · 1 line
2.37.2