summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorMark Becwar <mark@thebecwar.com>2019-02-02 21:08:23 (GMT)
committerSteve Dower <steve.dower@microsoft.com>2019-02-02 21:08:23 (GMT)
commitb82bfac4369c0429e562a834b3752e66c4821eab (patch)
tree24cb35ba11a8bd4e00d69b38081b85e17d4ebd31 /Modules/posixmodule.c
parentcb0904762681031edc50f9d7d7ef48cffcf96d9a (diff)
downloadcpython-b82bfac4369c0429e562a834b3752e66c4821eab.zip
cpython-b82bfac4369c0429e562a834b3752e66c4821eab.tar.gz
cpython-b82bfac4369c0429e562a834b3752e66c4821eab.tar.bz2
bpo-29734: nt._getfinalpathname handle leak (GH-740)
Make sure that failure paths call CloseHandle outside of the function that failed
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 931c0d3..80add7d 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -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);