diff --git a/PIL/Image.py b/PIL/Image.py index 60981cb3c..4e458dde5 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -565,6 +565,9 @@ class Image(object): except Exception as msg: logger.debug("Error closing: %s", msg) + if getattr(self, 'map', None): + self.map = None + # Instead of simply setting to None, we're setting up a # deferred error that will better explain that the core image # object is gone. diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index 12189a0eb..81f135115 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -490,6 +490,7 @@ class TestFileTiffW32(PillowTestCase): tmpfile = self.tempfile("temp.tif") import os + # this is an mmaped file. with Image.open("Tests/images/uint16_1_4660.tif") as im: im.save(tmpfile) @@ -499,7 +500,12 @@ class TestFileTiffW32(PillowTestCase): self.assertRaises(Exception, lambda: os.remove(tmpfile)) im.load() self.assertTrue(fp.closed) - # this should not fail, as load should have closed the file. + + # this closes the mmap + im.close() + + # this should not fail, as load should have closed the file pointer, + # and close should have closed the mmap os.remove(tmpfile) if __name__ == '__main__':