Skip to contentSkip to conversation

xend: fix open file descriptor leak

PATCH In review Kouya Shimura 2 participants 2 messages Jan 20, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xend: fix open file descriptor leak

I got the following error:

$ xm pci-list-assignable-devices
Error: [Errno 24] Too many open files
tools/python/xen/util/pci.py +4 -0
diff -r d1631540bcc4 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

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

Kouya Shimura writes ("[Xen-devel] [PATCH] xend: fix open file descriptor leak"):

Quoted 4 lines

I got the following error:

$ xm pci-list-assignable-devices
Error: [Errno 24] Too many open files

Thanks, I have applied your patch.

Ian.