avoid file descriptor leak when fd == 0

* src/pci.c (pciGetDevice): Initialize dev->fd to -1, not 0.
(pciFreeDevice): Close fd also when it is 0.
This commit is contained in:
Jim Meyering 2009-03-03 11:25:52 +00:00
parent 8343dcb893
commit 10e3148f0a
2 changed files with 8 additions and 1 deletions

View File

@ -1,3 +1,9 @@
Tue Mar 3 12:22:51 +0100 2009 Jim Meyering <meyering@redhat.com>
avoid file descriptor leak when fd == 0
* src/pci.c (pciGetDevice): Initialize dev->fd to -1, not 0.
(pciFreeDevice): Close fd also when it is 0.
Tue Mar 3 12:22:51 +0100 2009 Jim Meyering <meyering@redhat.com>
don't leak a file descriptor on failed pciGetDevice call

View File

@ -789,6 +789,7 @@ pciGetDevice(virConnectPtr conn,
return NULL;
}
dev->fd = -1;
dev->domain = domain;
dev->bus = bus;
dev->slot = slot;
@ -827,7 +828,7 @@ void
pciFreeDevice(virConnectPtr conn ATTRIBUTE_UNUSED, pciDevice *dev)
{
VIR_DEBUG("%s %s: freeing", dev->id, dev->name);
if (dev->fd)
if (dev->fd >= 0)
close(dev->fd);
VIR_FREE(dev);
}