Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c36674a

Browse files
committed
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.
1 parent ad52437 commit c36674a

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

Modules/posixmodule.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,7 +1463,7 @@ get_target_path(HANDLE hdl, wchar_t **target_path)
14631463
if(!buf_size)
14641464
return FALSE;
14651465

1466-
buf = PyMem_New(wchar_t, buf_size+1);
1466+
buf = (wchar_t *)PyMem_RawMalloc((buf_size + 1) * sizeof(wchar_t));
14671467
if (!buf) {
14681468
SetLastError(ERROR_OUTOFMEMORY);
14691469
return FALSE;
@@ -1473,12 +1473,12 @@ get_target_path(HANDLE hdl, wchar_t **target_path)
14731473
buf, buf_size, VOLUME_NAME_DOS);
14741474

14751475
if(!result_length) {
1476-
PyMem_Free(buf);
1476+
PyMem_RawFree(buf);
14771477
return FALSE;
14781478
}
14791479

14801480
if(!CloseHandle(hdl)) {
1481-
PyMem_Free(buf);
1481+
PyMem_RawFree(buf);
14821482
return FALSE;
14831483
}
14841484

@@ -1563,7 +1563,7 @@ win32_xstat_impl(const char *path, struct _Py_stat_struct *result,
15631563
return -1;
15641564

15651565
code = win32_xstat_impl_w(target_path, result, FALSE);
1566-
PyMem_Free(target_path);
1566+
PyMem_RawFree(target_path);
15671567
return code;
15681568
}
15691569
} else
@@ -1653,7 +1653,7 @@ win32_xstat_impl_w(const wchar_t *path, struct _Py_stat_struct *result,
16531653
return -1;
16541654

16551655
code = win32_xstat_impl_w(target_path, result, FALSE);
1656-
PyMem_Free(target_path);
1656+
PyMem_RawFree(target_path);
16571657
return code;
16581658
}
16591659
} else

0 commit comments

Comments
 (0)