diff --git a/ChangeLog b/ChangeLog index bae760e693..67dedb55df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Tue Mar 3 12:22:51 +0100 2009 Jim Meyering + + 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 don't leak a file descriptor on failed pciGetDevice call diff --git a/src/pci.c b/src/pci.c index 29a6dcc200..b9c781b46d 100644 --- a/src/pci.c +++ b/src/pci.c @@ -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); }