@@ -1620,7 +1620,7 @@ get_target_path(HANDLE hdl, wchar_t **target_path)
16201620 if (!buf_size )
16211621 return FALSE;
16221622
1623- buf = (wchar_t * ) PyMem_Malloc (( buf_size + 1 ) * sizeof ( wchar_t ) );
1623+ buf = PyMem_New (wchar_t , buf_size + 1 );
16241624 if (!buf ) {
16251625 SetLastError (ERROR_OUTOFMEMORY );
16261626 return FALSE;
@@ -4472,7 +4472,7 @@ _listdir_windows_no_opendir(path_t *path, PyObject *list)
44724472 len = wcslen (path -> wide );
44734473 }
44744474 /* The +5 is so we can append "\\*.*\0" */
4475- wnamebuf = PyMem_Malloc (( len + 5 ) * sizeof ( wchar_t ) );
4475+ wnamebuf = PyMem_New ( wchar_t , len + 5 );
44764476 if (!wnamebuf ) {
44774477 PyErr_NoMemory ();
44784478 goto exit ;
@@ -4809,7 +4809,7 @@ posix__getfullpathname(PyObject *self, PyObject *args)
48094809 Py_ARRAY_LENGTH (woutbuf ),
48104810 woutbuf , & wtemp );
48114811 if (result > Py_ARRAY_LENGTH (woutbuf )) {
4812- woutbufp = PyMem_Malloc ( result * sizeof ( wchar_t ) );
4812+ woutbufp = PyMem_New ( wchar_t , result );
48134813 if (!woutbufp )
48144814 return PyErr_NoMemory ();
48154815 result = GetFullPathNameW (wpath , result , woutbufp , & wtemp );
@@ -4923,7 +4923,7 @@ os__getfinalpathname_impl(PyModuleDef *module, PyObject *path)
49234923 if (!buf_size )
49244924 return win32_error_object ("GetFinalPathNameByHandle" , path );
49254925
4926- target_path = (wchar_t * ) PyMem_Malloc (( buf_size + 1 ) * sizeof ( wchar_t ) );
4926+ target_path = PyMem_New (wchar_t , buf_size + 1 );
49274927 if (!target_path )
49284928 return PyErr_NoMemory ();
49294929
@@ -5041,7 +5041,7 @@ os__getvolumepathname_impl(PyModuleDef *module, PyObject *path)
50415041 return NULL ;
50425042 }
50435043
5044- mountpath = (wchar_t * ) PyMem_Malloc ( buflen * sizeof ( wchar_t ) );
5044+ mountpath = PyMem_New (wchar_t , buflen );
50455045 if (mountpath == NULL )
50465046 return PyErr_NoMemory ();
50475047
@@ -8421,9 +8421,9 @@ posix_getgrouplist(PyObject *self, PyObject *args)
84218421#endif
84228422
84238423#ifdef __APPLE__
8424- groups = PyMem_Malloc ( ngroups * sizeof ( int ) );
8424+ groups = PyMem_New ( int , ngroups );
84258425#else
8426- groups = PyMem_Malloc ( ngroups * sizeof ( gid_t ) );
8426+ groups = PyMem_New ( gid_t , ngroups );
84278427#endif
84288428 if (groups == NULL )
84298429 return PyErr_NoMemory ();
@@ -8523,7 +8523,7 @@ os_getgroups_impl(PyModuleDef *module)
85238523 /* groups will fit in existing array */
85248524 alt_grouplist = grouplist ;
85258525 } else {
8526- alt_grouplist = PyMem_Malloc ( n * sizeof ( gid_t ) );
8526+ alt_grouplist = PyMem_New ( gid_t , n );
85278527 if (alt_grouplist == NULL ) {
85288528 errno = EINVAL ;
85298529 return posix_error ();
@@ -8549,7 +8549,7 @@ os_getgroups_impl(PyModuleDef *module)
85498549 /* Avoid malloc(0) */
85508550 alt_grouplist = grouplist ;
85518551 } else {
8552- alt_grouplist = PyMem_Malloc ( n * sizeof ( gid_t ) );
8552+ alt_grouplist = PyMem_New ( gid_t , n );
85538553 if (alt_grouplist == NULL ) {
85548554 errno = EINVAL ;
85558555 return posix_error ();
0 commit comments