Kaydet (Commit) c36674a2 authored tarafından Victor Stinner's avatar Victor Stinner

Fix usage of PyMem_Malloc() in os.stat()

Issue #26563: Replace PyMem_Malloc() with PyMem_RawMalloc() in the Windows
implementation of os.stat(), since the code is called without holding the GIL.
üst ad524375
...@@ -1463,7 +1463,7 @@ get_target_path(HANDLE hdl, wchar_t **target_path) ...@@ -1463,7 +1463,7 @@ get_target_path(HANDLE hdl, wchar_t **target_path)
if(!buf_size) if(!buf_size)
return FALSE; return FALSE;
buf = PyMem_New(wchar_t, buf_size+1); buf = (wchar_t *)PyMem_RawMalloc((buf_size + 1) * sizeof(wchar_t));
if (!buf) { if (!buf) {
SetLastError(ERROR_OUTOFMEMORY); SetLastError(ERROR_OUTOFMEMORY);
return FALSE; return FALSE;
...@@ -1473,12 +1473,12 @@ get_target_path(HANDLE hdl, wchar_t **target_path) ...@@ -1473,12 +1473,12 @@ get_target_path(HANDLE hdl, wchar_t **target_path)
buf, buf_size, VOLUME_NAME_DOS); buf, buf_size, VOLUME_NAME_DOS);
if(!result_length) { if(!result_length) {
PyMem_Free(buf); PyMem_RawFree(buf);
return FALSE; return FALSE;
} }
if(!CloseHandle(hdl)) { if(!CloseHandle(hdl)) {
PyMem_Free(buf); PyMem_RawFree(buf);
return FALSE; return FALSE;
} }
...@@ -1563,7 +1563,7 @@ win32_xstat_impl(const char *path, struct _Py_stat_struct *result, ...@@ -1563,7 +1563,7 @@ win32_xstat_impl(const char *path, struct _Py_stat_struct *result,
return -1; return -1;
code = win32_xstat_impl_w(target_path, result, FALSE); code = win32_xstat_impl_w(target_path, result, FALSE);
PyMem_Free(target_path); PyMem_RawFree(target_path);
return code; return code;
} }
} else } else
...@@ -1653,7 +1653,7 @@ win32_xstat_impl_w(const wchar_t *path, struct _Py_stat_struct *result, ...@@ -1653,7 +1653,7 @@ win32_xstat_impl_w(const wchar_t *path, struct _Py_stat_struct *result,
return -1; return -1;
code = win32_xstat_impl_w(target_path, result, FALSE); code = win32_xstat_impl_w(target_path, result, FALSE);
PyMem_Free(target_path); PyMem_RawFree(target_path);
return code; return code;
} }
} else } else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment