All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matt Wilson <msw@linux.com>
To: xen-devel@lists.xenproject.org
Cc: Ian Campbell <ian.campbell@citrix.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>,
	Xi Xiong <xixiong@amazon.com>, Matt Wilson <msw@amazon.com>,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: [PATCH] xend: fix file descriptor leak in pci utilities
Date: Fri, 30 Aug 2013 12:21:56 -0700	[thread overview]
Message-ID: <1377890516-3235-1-git-send-email-msw@linux.com> (raw)

From: Xi Xiong <xixiong@amazon.com>

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]
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Matt Wilson <msw@amazon.com>
---
 tools/python/xen/util/pci.py |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/python/xen/util/pci.py b/tools/python/xen/util/pci.py
index 98bea1a..792fb69 100644
--- a/tools/python/xen/util/pci.py
+++ b/tools/python/xen/util/pci.py
@@ -968,18 +968,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:
@@ -989,6 +993,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
-- 
1.7.9.5

                 reply	other threads:[~2013-08-30 19:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1377890516-3235-1-git-send-email-msw@linux.com \
    --to=msw@linux.com \
    --cc=ian.campbell@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=msw@amazon.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    --cc=xixiong@amazon.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.