diff options
author | Kouya Shimura <kouya@jp.fujitsu.com> | 2011-01-20 16:41:23 +0000 |
---|---|---|
committer | Kouya Shimura <kouya@jp.fujitsu.com> | 2011-01-20 16:41:23 +0000 |
commit | c398531ffaf46fb275782f0935a332094a17a030 (patch) | |
tree | bcdfef16a001afc36acc3efa2a2c45f3120d59ca /tools/python | |
parent | 1da4ffed6fc715d2593f96925ecb98773b1de8df (diff) | |
download | xen-c398531ffaf46fb275782f0935a332094a17a030.tar.gz xen-c398531ffaf46fb275782f0935a332094a17a030.tar.bz2 xen-c398531ffaf46fb275782f0935a332094a17a030.zip |
xend: pci.py: fix open file descriptor leak
I got the following error:
$ xm pci-list-assignable-devices
Error: [Errno 24] Too many open files
Signed-off-by: Kouya Shimura <kouya@jp.fujitsu.com>
Diffstat (limited to 'tools/python')
-rw-r--r-- | tools/python/xen/util/pci.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/tools/python/xen/util/pci.py b/tools/python/xen/util/pci.py index 2fad278aa6..b889d1816e 100644 --- a/tools/python/xen/util/pci.py +++ b/tools/python/xen/util/pci.py @@ -922,10 +922,12 @@ class PciDevice: pos = PCI_CAPABILITY_LIST try: + fd = None fd = os.open(path, os.O_RDONLY) os.lseek(fd, PCI_STATUS, 0) status = struct.unpack('H', os.read(fd, 2))[0] if (status & 0x10) == 0: + os.close(fd) # The device doesn't support PCI_STATUS_CAP_LIST return 0 @@ -952,6 +954,8 @@ class PciDevice: os.close(fd) except OSError, (errno, strerr): + if fd is not None: + os.close(fd) raise PciDeviceParseError(('Error when accessing sysfs: %s (%d)' % (strerr, errno))) return pos |