diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-01-25 19:43:56 +0200 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-01-25 19:43:56 +0200 |
commit | c0b0bb6e01f7ea6a1a857609e794842223c4aa5c (patch) | |
tree | 23a00341a5a15f7af05ecd0549eb729dd906788a /Lib/imghdr.py | |
parent | a3642b67ca2656ec6d5c10a52bbb643462236ded (diff) | |
parent | 91b0bc237c07b52c771e121098989680cfc3600d (diff) | |
download | cpython-git-c0b0bb6e01f7ea6a1a857609e794842223c4aa5c.tar.gz |
Issue #20331: Fixed possible FD leaks in various modules:
http.server, imghdr, mailcap, mimetypes, xml.etree.
Diffstat (limited to 'Lib/imghdr.py')
-rw-r--r-- | Lib/imghdr.py | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/Lib/imghdr.py b/Lib/imghdr.py index 0cba063a9c..add2ea8898 100644 --- a/Lib/imghdr.py +++ b/Lib/imghdr.py @@ -7,18 +7,16 @@ __all__ = ["what"] #-------------------------# def what(file, h=None): - if h is None: - if isinstance(file, str): - f = open(file, 'rb') - h = f.read(32) - else: - location = file.tell() - h = file.read(32) - file.seek(location) - f = None - else: - f = None + f = None try: + if h is None: + if isinstance(file, str): + f = open(file, 'rb') + h = f.read(32) + else: + location = file.tell() + h = file.read(32) + file.seek(location) for tf in tests: res = tf(h, f) if res: |