diff --git a/src/PIL/ImageFile.py b/src/PIL/ImageFile.py index 339917ab7..63a9d4ca2 100644 --- a/src/PIL/ImageFile.py +++ b/src/PIL/ImageFile.py @@ -174,8 +174,8 @@ class ImageFile(Image.Image): else: # use mmap, if possible import mmap - fp = open(self.filename, "r") - self.map = mmap.mmap(fp.fileno(), 0, access=mmap.ACCESS_READ) + with open(self.filename, "r") as fp: + self.map = mmap.mmap(fp.fileno(), 0, access=mmap.ACCESS_READ) self.im = Image.core.map_buffer( self.map, self.size, decoder_name, extents, offset, args )