From 091d0c400caebc1268091a13251071c59e02077e Mon Sep 17 00:00:00 2001 From: homm Date: Sun, 17 Jul 2016 06:33:23 +0300 Subject: [PATCH] close fp if it was opened in ImageFile constructor --- PIL/ImageFile.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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