aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXi Xiong <xixiong@amazon.com>2013-09-12 11:28:03 +0200
committerJan Beulich <jbeulich@suse.com>2013-09-12 11:28:03 +0200
commit0605de0e2db799b30d3f93490132ba916034b289 (patch)
treee3bdd03200bf681c20b6a76108a323525b7a4399
parente7c05bbb21b4747693b5fc04a1da4aa6f44446fc (diff)
downloadxen-0605de0e2db799b30d3f93490132ba916034b289.tar.gz
xen-0605de0e2db799b30d3f93490132ba916034b289.tar.bz2
xen-0605de0e2db799b30d3f93490132ba916034b289.zip
xend: fix file descriptor leak in pci utilities
A file descriptor leak was detected after creating multiple domUs with pass-through PCI devices. This patch fixes the issue. Signed-off-by: Xi Xiong <xixiong@amazon.com> Reviewed-by: Matt Wilson <msw@amazon.com> [msw: adjusted commit message] Signed-off-by: Matt Wilson <msw@amazon.com> master commit: 749019afca4fd002d36856bad002cc11f7d0ddda master date: 2013-09-03 16:36:52 +0100
-rw-r--r--tools/python/xen/util/pci.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/tools/python/xen/util/pci.py b/tools/python/xen/util/pci.py
index 307144ce31..adeca4bbf9 100644
--- a/tools/python/xen/util/pci.py
+++ b/tools/python/xen/util/pci.py
@@ -969,18 +969,22 @@ class PciDevice:
ttl = 480; # 3840 bytes, minimum 8 bytes per capability
pos = 0x100
+ fd = None
try:
fd = os.open(path, os.O_RDONLY)
os.lseek(fd, pos, 0)
h = os.read(fd, 4)
if len(h) == 0: # MMCONF is not enabled?
+ os.close(fd)
return 0
header = struct.unpack('I', h)[0]
if header == 0 or header == -1:
+ os.close(fd)
return 0
while ttl > 0:
if (header & 0x0000ffff) == cap:
+ os.close(fd)
return pos
pos = (header >> 20) & 0xffc
if pos < 0x100:
@@ -990,6 +994,8 @@ class PciDevice:
ttl = ttl - 1
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 0