Skip to content

Fix handle leak in GetFinalPathName#1978

Open
tyrielv wants to merge 1 commit into
microsoft:masterfrom
tyrielv:tyrielv/fix-handle-leak-getfinalpathname
Open

Fix handle leak in GetFinalPathName#1978
tyrielv wants to merge 1 commit into
microsoft:masterfrom
tyrielv:tyrielv/fix-handle-leak-getfinalpathname

Conversation

@tyrielv
Copy link
Copy Markdown
Contributor

@tyrielv tyrielv commented May 19, 2026

The fileHandle obtained from CreateFileW in GetFinalPathName (common.windows.cpp) was never closed after calling GetFinalPathNameByHandleW, leaking a kernel handle on every invocation.

This adds CloseHandle(fileHandle) immediately after GetFinalPathNameByHandleW returns, before the error check — the handle is no longer needed once the API call completes.

The fileHandle obtained from CreateFileW was never closed after
calling GetFinalPathNameByHandleW, leaking a kernel handle on
every invocation. Add CloseHandle(fileHandle) on both the success
path and the error path before die().

Assisted-by: Claude Opus 4.6
Signed-off-by: Tyrie Vella <tyrielv@gmail.com>
@tyrielv tyrielv force-pushed the tyrielv/fix-handle-leak-getfinalpathname branch from 9c4cce8 to 55bcda1 Compare May 19, 2026 20:46
@tyrielv tyrielv marked this pull request as ready for review May 19, 2026 20:47
@tyrielv tyrielv enabled auto-merge May 19, 2026 20:47
@tyrielv tyrielv requested a review from KeithIsSleeping May 19, 2026 21:38
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