diff --git a/ChangeLog b/ChangeLog index bae760e6935fbe2d475f348b76d70327b8e721e9..67dedb55dfad82af2bd79ada2cd8659fcd9da61b 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 29a6dcc2000d82213679860bc9acce216fa2cc09..b9c781b46de3244f1e118f4a67be6ee4c76146e1 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); }