Skip to content

fix(foreground): close the process handle after reading the exe name - #1

Merged
kingchenc merged 1 commit into
mainfrom
fix/foreground-process-handle-leak
Oct 18, 2026
Merged

kingchenc merged 1 commit into
mainfrom
fix/foreground-process-handle-leak

Conversation

@kingchenc

Copy link
Copy Markdown
Owner

The foreground watcher (app/src-tauri/src/foreground.rs) calls OpenProcess for the focused window's process every 750 ms to read its exe name, but never closed the handle.

On a PC with 20 days of uptime the app held 1,285,805 handles, 99.97 % of them process handles, growing by about 1.3 per second.

Fix: the handle is wrapped in a small guard that calls CloseHandle on drop, so it is released on every path, including the early return when QueryFullProcessImageNameW fails.

Verified: a local release build ran for 90 s while the foreground window changed. The handle count stayed at about 350 (the old build gained about 126 in the same time). cargo fmt --check and cargo clippy for the app crate report no new warnings.

The foreground watcher opened the focused window's process with
OpenProcess every 750 ms and never closed the handle. Over 20 days of
uptime the app held 1.28 million process handles, growing by about
1.3 per second. The handle now lives in a guard that closes it on every
path, including when QueryFullProcessImageNameW fails.
@kingchenc
kingchenc merged commit 94bda30 into main Oct 18, 2026
7 checks passed
@kingchenc
kingchenc deleted the fix/foreground-process-handle-leak branch October 18, 2026 01:56
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