diff options
| author | Nick Coghlan <ncoghlan@gmail.com> | 2013-11-24 12:53:50 +1000 | 
|---|---|---|
| committer | Nick Coghlan <ncoghlan@gmail.com> | 2013-11-24 12:53:50 +1000 | 
| commit | 1889623e1a49e38df6d10171e4a4256dfcb8916b (patch) | |
| tree | 274f469580640d672379fc8747b20e3a953b02ec | |
| parent | 878d258a22c6f40401671dd329b76516a03a2b71 (diff) | |
| download | cpython-git-1889623e1a49e38df6d10171e4a4256dfcb8916b.tar.gz | |
Issue #19734: ctypes resource management fixes
| -rw-r--r-- | Lib/ctypes/util.py | 15 | 
1 files changed, 9 insertions, 6 deletions
| diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py index d2c04d2142..0cf20766cc 100644 --- a/Lib/ctypes/util.py +++ b/Lib/ctypes/util.py @@ -132,8 +132,10 @@ elif os.name == "posix":              cmd = 'if ! type objdump >/dev/null 2>&1; then exit 10; fi;' \                    "objdump -p -j .dynamic 2>/dev/null " + f              f = os.popen(cmd) -            dump = f.read() -            rv = f.close() +            try: +                dump = f.read() +            finally: +                rv = f.close()              if rv == 10:                  raise OSError('objdump command not found')              res = re.search(r'\sSONAME\s+([^\s]+)', dump) @@ -176,10 +178,11 @@ elif os.name == "posix":              else:                  cmd = 'env LC_ALL=C /usr/bin/crle 2>/dev/null' -            for line in os.popen(cmd).readlines(): -                line = line.strip() -                if line.startswith('Default Library Path (ELF):'): -                    paths = line.split()[4] +            with contextlib.closing(os.popen(cmd)) as f: +                for line in f.readlines(): +                    line = line.strip() +                    if line.startswith('Default Library Path (ELF):'): +                        paths = line.split()[4]              if not paths:                  return None | 
