mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
bpo-29734: nt._getfinalpathname handle leak (GH-740)
Make sure that failure paths call CloseHandle outside of the function that failed
This commit is contained in:
parent
cb09047626
commit
b82bfac436
3 changed files with 67 additions and 8 deletions
|
@ -1640,11 +1640,6 @@ get_target_path(HANDLE hdl, wchar_t **target_path)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
if(!CloseHandle(hdl)) {
|
||||
PyMem_RawFree(buf);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
buf[result_length] = 0;
|
||||
|
||||
*target_path = buf;
|
||||
|
@ -1702,9 +1697,10 @@ win32_xstat_impl(const wchar_t *path, struct _Py_stat_struct *result,
|
|||
return -1;
|
||||
}
|
||||
if (info.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
|
||||
if (!win32_get_reparse_tag(hFile, &reparse_tag))
|
||||
if (!win32_get_reparse_tag(hFile, &reparse_tag)) {
|
||||
CloseHandle(hFile);
|
||||
return -1;
|
||||
|
||||
}
|
||||
/* Close the outer open file handle now that we're about to
|
||||
reopen it with different flags. */
|
||||
if (!CloseHandle(hFile))
|
||||
|
@ -1721,8 +1717,14 @@ win32_xstat_impl(const wchar_t *path, struct _Py_stat_struct *result,
|
|||
if (hFile2 == INVALID_HANDLE_VALUE)
|
||||
return -1;
|
||||
|
||||
if (!get_target_path(hFile2, &target_path))
|
||||
if (!get_target_path(hFile2, &target_path)) {
|
||||
CloseHandle(hFile2);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!CloseHandle(hFile2)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
code = win32_xstat_impl(target_path, result, FALSE);
|
||||
PyMem_RawFree(target_path);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue