Skip to content

Commit 5d741fb

Browse files
committed
shot at preventing resource leak
So far this diverges from the rest of the codebase locations but let's see if it passes at least.
1 parent cd9870a commit 5d741fb

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

guibot/finder.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,8 +605,11 @@ def find(self, needle: "Image", haystack: "Image") -> "list[Match]":
605605
# TODO: Use in-memory conversion
606606
with NamedTemporaryFile(prefix="guibot", suffix=".png") as f:
607607
filename = f.name
608-
haystack.save(filename)
609-
autopy_screenshot = bitmap.Bitmap.open(filename)
608+
try:
609+
haystack.save(filename)
610+
autopy_screenshot = bitmap.Bitmap.open(filename)
611+
finally:
612+
os.unlink(filename)
610613

611614
autopy_tolerance = 1.0 - self.params["find"]["similarity"].value
612615
log.debug(

0 commit comments

Comments
 (0)