diff --git a/PIL/ImageFile.py b/PIL/ImageFile.py index 57391bcce..e1f7aed84 100644 --- a/PIL/ImageFile.py +++ b/PIL/ImageFile.py @@ -120,6 +120,8 @@ class ImageFile(Image.Image): # raise exception if something's wrong. must be called # directly after open, and closes file when finished. + if self._exclusive_fp: + self.fp.close() self.fp = None def load(self): @@ -239,7 +241,9 @@ class ImageFile(Image.Image): self.tile = [] self.readonly = readonly - self.fp = None # might be shared + if self._exclusive_fp: + self.fp.close() + self.fp = None if not self.map and not LOAD_TRUNCATED_IMAGES and err_code < 0: # still raised if decoder fails to return anything