unpaper: close images on error paths

This commit is contained in:
James R. Barlow
2018-04-09 13:05:12 -07:00
parent db8b0319dd
commit 11b6f77df0
+4 -4
View File
@@ -57,15 +57,15 @@ def run(input_file, output_file, dpi, log, mode_args):
else:
im = im.convert(mode='RGB')
except IOError as e:
log.error(
"Could not convert image with type " + im.mode)
log.error("Could not convert image with type " + im.mode)
im.close()
raise MissingDependencyError() from e
try:
suffix = SUFFIXES[im.mode]
except KeyError:
log.error(
"Failed to convert image to a supported format.")
log.error("Failed to convert image to a supported format.")
im.close()
raise MissingDependencyError() from e
with NamedTemporaryFile(suffix=suffix) as input_pnm, \