[PATCHv2 10/12] pci: eliminate leak in OOM condition

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/src/util/virpci.c b/src/util/virpci.c
index 378b4f3..515feea 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -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;
-- 
1.7.11.7

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]