spapr_pci: fix leak in spapr_phb_vfio_get_loc_code
authorPaolo Bonzini <pbonzini@redhat.com>
Mon, 5 Sep 2022 10:17:45 +0000 (12:17 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Sun, 18 Sep 2022 07:17:40 +0000 (09:17 +0200)
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.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
hw/ppc/spapr_pci.c

index 67e9d468aa9c30cdb036d93597ec4f3353806480..57c8a4f0855a2a55a54e8e9d7356f431cec2a572 100644 (file)
@@ -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;