Skip to content

Commit 9c4cce8

Browse files
committed
Fix handle leak in GetFinalPathName
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>
1 parent 1e748bb commit 9c4cce8

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

GVFS/GVFS.NativeHooks.Common/common.windows.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ PATH_STRING GetFinalPathName(const PATH_STRING& path)
3030
DWORD finalPathSize = GetFinalPathNameByHandleW(fileHandle, finalPathByHandle, MAX_PATH, FILE_NAME_NORMALIZED);
3131
if (finalPathSize == 0)
3232
{
33+
CloseHandle(fileHandle);
3334
die(ReturnCode::PathNameError, "Could not get final path name by handle for %ls, Error: %d\n", path.c_str(), GetLastError());
3435
}
3536

37+
CloseHandle(fileHandle);
38+
3639
std::wstring finalPath(finalPathByHandle);
3740

3841
// The remarks section of GetFinalPathNameByHandle mentions the return being prefixed with "\\?\" or "\\?\UNC\"

0 commit comments

Comments
 (0)