]> xenbits.xensource.com Git - people/dariof/libvirt.git/commitdiff
pci: eliminate leak in OOM condition
authorLaine Stump <laine@laine.org>
Tue, 25 Jun 2013 01:30:55 +0000 (21:30 -0400)
committerLaine Stump <laine@laine.org>
Tue, 25 Jun 2013 22:24:43 +0000 (18:24 -0400)
The "fix" I pushed a few commits ago would still leak a virPCIDevice
in case of an OOM error. Although it's inconsequential in practice,
this patch satisfies my OCD.

src/util/virpci.c

index a64e41070f12b59c91ec99ba5d93a04fe4f44d90..32a54932cd4c0409db150c807954ed26c5ca9939 100644 (file)
@@ -1268,11 +1268,9 @@ virPCIDeviceDetach(virPCIDevicePtr dev,
     /* Add *a copy of* the dev into list inactiveDevs, if
      * it's not already there.
      */
-    if (inactiveDevs && !virPCIDeviceListFind(inactiveDevs, dev)) {
-        virPCIDevicePtr copy = virPCIDeviceCopy(dev);
-
-        if ((!copy) || virPCIDeviceListAdd(inactiveDevs, copy) < 0)
-            return -1;
+    if (inactiveDevs && !virPCIDeviceListFind(inactiveDevs, dev) &&
+        virPCIDeviceListAddCopy(inactiveDevs, dev) < 0) {
+        return -1;
     }
 
     return 0;