summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-12-12 20:26:00 (GMT)
committerGuido van Rossum <guido@python.org>2007-12-12 20:26:00 (GMT)
commitf4d4f8b97fc2e5a59058c54abe6a23194c3d3116 (patch)
tree7af44e2fb7732038e884c2221beb8e14147bfcdd /Lib
parentb8189f3b5a2f7e14218934daf909e1ffd8800a0b (diff)
downloadcpython-f4d4f8b97fc2e5a59058c54abe6a23194c3d3116.zip
cpython-f4d4f8b97fc2e5a59058c54abe6a23194c3d3116.tar.gz
cpython-f4d4f8b97fc2e5a59058c54abe6a23194c3d3116.tar.bz2
Explicitly close pipes so test_ctypes won't appear to randomly leak
+33 or -33 references. (See discussion in #1597.)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/ctypes/util.py43
1 files changed, 34 insertions, 9 deletions
diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
index 629e383..733a99c 100644
--- a/Lib/ctypes/util.py
+++ b/Lib/ctypes/util.py
@@ -50,8 +50,10 @@ elif os.name == "posix":
'$CC -Wl,-t -o ' + ccout + ' 2>&1 -l' + name
try:
f = os.popen(cmd)
- trace = f.read()
- f.close()
+ try:
+ trace = f.read()
+ finally:
+ f.close()
finally:
try:
os.unlink(ccout)
@@ -70,7 +72,12 @@ elif os.name == "posix":
if not f:
return None
cmd = "/usr/ccs/bin/dump -Lpv 2>/dev/null " + f
- res = re.search(r'\[.*\]\sSONAME\s+([^\s]+)', os.popen(cmd).read())
+ f = os.popen(cmd)
+ try:
+ data = f.read()
+ finally:
+ f.close()
+ res = re.search(r'\[.*\]\sSONAME\s+([^\s]+)', data)
if not res:
return None
return res.group(1)
@@ -80,7 +87,12 @@ elif os.name == "posix":
if not f:
return None
cmd = "objdump -p -j .dynamic 2>/dev/null " + f
- res = re.search(r'\sSONAME\s+([^\s]+)', os.popen(cmd).read())
+ f = os.popen(cmd)
+ try:
+ data = f.read()
+ finally:
+ f.close()
+ res = re.search(r'\sSONAME\s+([^\s]+)', data)
if not res:
return None
return res.group(1)
@@ -103,8 +115,12 @@ elif os.name == "posix":
def find_library(name):
ename = re.escape(name)
expr = r':-l%s\.\S+ => \S*/(lib%s\.\S+)' % (ename, ename)
- res = re.findall(expr,
- os.popen('/sbin/ldconfig -r 2>/dev/null').read())
+ f = os.popen('/sbin/ldconfig -r 2>/dev/null')
+ try:
+ data = f.read()
+ finally:
+ f.close()
+ res = re.findall(expr, data)
if not res:
return _get_soname(_findLib_gcc(name))
res.sort(cmp= lambda x,y: cmp(_num_version(x), _num_version(y)))
@@ -115,12 +131,21 @@ elif os.name == "posix":
def _findLib_ldconfig(name):
# XXX assuming GLIBC's ldconfig (with option -p)
expr = r'/[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name)
- res = re.search(expr,
- os.popen('/sbin/ldconfig -p 2>/dev/null').read())
+ f = os.popen('/sbin/ldconfig -p 2>/dev/null')
+ try:
+ data = f.read()
+ finally:
+ f.close()
+ res = re.search(expr, data)
if not res:
# Hm, this works only for libs needed by the python executable.
cmd = 'ldd %s 2>/dev/null' % sys.executable
- res = re.search(expr, os.popen(cmd).read())
+ f = os.popen(cmd)
+ try:
+ data = f.read()
+ finally:
+ f.close()
+ res = re.search(expr, data)
if not res:
return None
return res.group(0)