diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-01-25 17:43:02 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-01-25 17:43:02 (GMT) |
commit | 91b0bc237c07b52c771e121098989680cfc3600d (patch) | |
tree | 96ce4b2c32292bf2f619846c1599c9af0142f2f7 /Lib/imghdr.py | |
parent | 933209689e8d07e3ce00c68ca26e001b130f0b62 (diff) | |
download | cpython-91b0bc237c07b52c771e121098989680cfc3600d.zip cpython-91b0bc237c07b52c771e121098989680cfc3600d.tar.gz cpython-91b0bc237c07b52c771e121098989680cfc3600d.tar.bz2 |
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 6ee45da..bdd47ee 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: |