[libvirt] [PATCH 05/17] Fix leak of address string in qemuDomainPCIAddressGetNextSlot

Daniel P. Berrange berrange at redhat.com
Tue Sep 24 16:03:55 UTC 2013


From: "Daniel P. Berrange" <berrange at redhat.com>

qemuDomainPCIAddressGetNextSlot has a loop for finding
compatible PCI buses. In the loop body it creates a
PCI address string, but never frees this. This causes
a leak if the loop executes more than one iteration,
or if a call in the loop body fails.

Signed-off-by: Daniel P. Berrange <berrange at redhat.com>
---
 src/qemu/qemu_command.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 0376611..3296d09 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2194,12 +2194,12 @@ qemuDomainPCIAddressGetNextSlot(qemuDomainPCIAddressSetPtr addrs,
 
     /* Start the search at the last used bus and slot */
     for (a.slot++; a.bus < addrs->nbuses; a.bus++) {
-        addrStr = NULL;
         if (!(addrStr = qemuDomainPCIAddressAsString(&a)))
             goto error;
         if (!qemuDomainPCIAddressFlagsCompatible(&a, addrStr,
                                                  addrs->buses[a.bus].flags,
                                                  flags, false, false)) {
+            VIR_FREE(addrStr);
             VIR_DEBUG("PCI bus %.4x:%.2x is not compatible with the device",
                       a.domain, a.bus);
             continue;
@@ -2212,6 +2212,7 @@ qemuDomainPCIAddressGetNextSlot(qemuDomainPCIAddressSetPtr addrs,
                       a.domain, a.bus, a.slot);
         }
         a.slot = 1;
+        VIR_FREE(addrStr);
     }
 
     /* There were no free slots after the last used one */
-- 
1.8.3.1




More information about the libvir-list mailing list