diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-01-25 17:42:27 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-01-25 17:42:27 (GMT) |
commit | 1adbacfd1c80f4f724c5d515e48a518d0b1be2dd (patch) | |
tree | c2c0e80d7163597cd158aaad1626720b418b1fda /Lib/imghdr.py | |
parent | d8be9feb45baab60959d4076dc997062b307206f (diff) | |
download | cpython-1adbacfd1c80f4f724c5d515e48a518d0b1be2dd.zip cpython-1adbacfd1c80f4f724c5d515e48a518d0b1be2dd.tar.gz cpython-1adbacfd1c80f4f724c5d515e48a518d0b1be2dd.tar.bz2 |
Issue #20331: Fixed possible FD leaks in various modules:
SimpleHTTPServer, 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 1683024..fc864c3 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, basestring): - 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, basestring): + 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: |