Skip to content

Commit

Permalink
Remove temporary file when error is raised
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jun 6, 2023
1 parent 07be6aa commit 3b65261
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/PIL/EpsImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ def Ghostscript(tile, size, fp, scale=1, transparency=False):

if gs_windows_binary is not None:
if not gs_windows_binary:
try:
os.unlink(outfile)
if infile_temp:
os.unlink(infile_temp)
except OSError:
pass

msg = "Unable to locate Ghostscript on paths"
raise OSError(msg)
command[0] = gs_windows_binary
Expand Down
5 changes: 5 additions & 0 deletions src/PIL/JpegImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,11 @@ def load_djpeg(self):
if os.path.exists(self.filename):
subprocess.check_call(["djpeg", "-outfile", path, self.filename])
else:
try:
os.unlink(path)
except OSError:
pass

msg = "Invalid Filename"
raise ValueError(msg)

Expand Down

0 comments on commit 3b65261

Please sign in to comment.