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:
Mark Becwar 2019-02-02 16:08:23 -05:00 committed by Steve Dower
parent cb09047626
commit b82bfac436
3 changed files with 67 additions and 8 deletions

View file

@ -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);