Skip to content

fix: ensure temp screenshot file cleanup on error paths - #418

Open
Ricardo-M-L wants to merge 1 commit into
zai-org:mainfrom
Ricardo-M-L:fix/screenshot-temp-file-leak
Open

fix: ensure temp screenshot file cleanup on error paths#418
Ricardo-M-L wants to merge 1 commit into
zai-org:mainfrom
Ricardo-M-L:fix/screenshot-temp-file-leak

Conversation

@Ricardo-M-L

Copy link
Copy Markdown

What this PR fixes

The ADB screenshot capture flow creates a temporary file in the system temp directory, but only cleaned it up in the happy-path execution. If Image.open() or any downstream operation (save, base64 encode) raised an exception, the temp file would leak in /tmp/.

Changes

  • Move os.remove(temp_path) from the success path into a finally block
  • The finally block checks os.path.exists(temp_path) before removing, making it safe for all code paths including early returns for sensitive screens

Why this matters

Long-running automation sessions that encounter repeated screenshot errors can accumulate orphaned temp files, eventually filling the temp directory and causing filesystem issues.

Previously, the temp file created during ADB screenshot capture
was only removed in the happy path. If Image.open() or any
downstream operation raised an exception, the temp file would
leak in the system temp directory.

Move cleanup to a finally block to guarantee removal regardless
of the code path taken.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant