summaryrefslogtreecommitdiff
path: root/Lib/imghdr.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-01-25 19:43:56 +0200
committerSerhiy Storchaka <storchaka@gmail.com>2014-01-25 19:43:56 +0200
commitc0b0bb6e01f7ea6a1a857609e794842223c4aa5c (patch)
tree23a00341a5a15f7af05ecd0549eb729dd906788a /Lib/imghdr.py
parenta3642b67ca2656ec6d5c10a52bbb643462236ded (diff)
parent91b0bc237c07b52c771e121098989680cfc3600d (diff)
downloadcpython-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.py20
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: