]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Fix leak of address string in qemuDomainPCIAddressGetNextSlot
authorDaniel P. Berrange <berrange@redhat.com>
Tue, 24 Sep 2013 15:13:44 +0000 (16:13 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 25 Sep 2013 14:49:12 +0000 (15:49 +0100)
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@redhat.com>
src/qemu/qemu_command.c

index 38dd4517d1dd68ef465d3bd118175708596f6f19..1a364acf150106f1231103bdff5e52cf22e87b57 100644 (file)
@@ -2246,12 +2246,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;
@@ -2264,6 +2264,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 */