close the mmap when closing the image #2194

This commit is contained in:
wiredfool 2017-04-03 08:05:56 -07:00
parent db338ca19a
commit 06b61f4e5b
2 changed files with 10 additions and 1 deletions

View File

@ -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.

View File

@ -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__':