WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] xend: fix open file descriptor leak

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] xend: fix open file descriptor leak
From: Kouya Shimura <kouya@xxxxxxxxxxxxxx>
Date: Thu, 20 Jan 2011 13:24:12 +0900
Delivery-date: Wed, 19 Jan 2011 20:25:14 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
I got the following error:

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

Signed-off-by: Kouya Shimura <kouya@xxxxxxxxxxxxxx>

diff -r d1631540bcc4 tools/python/xen/util/pci.py
--- a/tools/python/xen/util/pci.py      Tue Jan 18 17:23:24 2011 +0000
+++ b/tools/python/xen/util/pci.py      Thu Jan 20 13:08:11 2011 +0900
@@ -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
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
<Prev in Thread] Current Thread [Next in Thread>