From: Laine Stump Date: Tue, 25 Jun 2013 01:30:55 +0000 (-0400) Subject: pci: eliminate leak in OOM condition X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=2a2739a8664c9f9dc3f08db8a272e5bf7b6af5db;p=people%2Fdariof%2Flibvirt.git pci: eliminate leak in OOM condition 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. --- diff --git a/src/util/virpci.c b/src/util/virpci.c index a64e41070..32a54932c 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;