Close exclusive fp on open exception

This commit is contained in:
Andrew Murray 2018-11-09 11:35:08 +11:00
parent 3d76a686c4
commit 747eccbfc2
2 changed files with 13 additions and 5 deletions

View File

@ -17,11 +17,15 @@ class TestBmpReference(PillowTestCase):
""" These shouldn't crash/dos, but they shouldn't return anything
either """
for f in self.get_files('b'):
try:
im = Image.open(f)
im.load()
except Exception: # as msg:
pass
def open(f):
try:
im = Image.open(f)
im.load()
except Exception: # as msg:
pass
# Assert that there is no unclosed file warning
self.assert_warning(None, open, f)
def test_questionable(self):
""" These shouldn't crash/dos, but it's not well defined that these

View File

@ -2641,6 +2641,10 @@ def open(fp, mode="r"):
# opening failures that are entirely expected.
# logger.debug("", exc_info=True)
continue
except Exception:
if exclusive_fp:
fp.close()
raise
return None
im = _open_core(fp, filename, prefix)