@@ -1298,14 +1298,14 @@ win32_wchdir(LPCWSTR path)
12981298 if (!result )
12991299 return FALSE;
13001300 if (result > MAX_PATH + 1 ) {
1301- new_path = malloc (result * sizeof (wchar_t ));
1301+ new_path = PyMem_RawMalloc (result * sizeof (wchar_t ));
13021302 if (!new_path ) {
13031303 SetLastError (ERROR_OUTOFMEMORY );
13041304 return FALSE;
13051305 }
13061306 result = GetCurrentDirectoryW (result , new_path );
13071307 if (!result ) {
1308- free (new_path );
1308+ PyMem_RawFree (new_path );
13091309 return FALSE;
13101310 }
13111311 }
@@ -1316,7 +1316,7 @@ win32_wchdir(LPCWSTR path)
13161316 env [1 ] = new_path [0 ];
13171317 result = SetEnvironmentVariableW (env , new_path );
13181318 if (new_path != _new_path )
1319- free (new_path );
1319+ PyMem_RawFree (new_path );
13201320 return result ;
13211321}
13221322#endif
@@ -1497,7 +1497,7 @@ get_target_path(HANDLE hdl, wchar_t **target_path)
14971497 if (!buf_size )
14981498 return FALSE;
14991499
1500- buf = (wchar_t * )malloc ((buf_size + 1 )* sizeof (wchar_t ));
1500+ buf = (wchar_t * )PyMem_Malloc ((buf_size + 1 )* sizeof (wchar_t ));
15011501 if (!buf ) {
15021502 SetLastError (ERROR_OUTOFMEMORY );
15031503 return FALSE;
@@ -1507,12 +1507,12 @@ get_target_path(HANDLE hdl, wchar_t **target_path)
15071507 buf , buf_size , VOLUME_NAME_DOS );
15081508
15091509 if (!result_length ) {
1510- free (buf );
1510+ PyMem_Free (buf );
15111511 return FALSE;
15121512 }
15131513
15141514 if (!CloseHandle (hdl )) {
1515- free (buf );
1515+ PyMem_Free (buf );
15161516 return FALSE;
15171517 }
15181518
@@ -1603,7 +1603,7 @@ win32_xstat_impl(const char *path, struct win32_stat *result,
16031603 return -1 ;
16041604
16051605 code = win32_xstat_impl_w (target_path , result , FALSE);
1606- free (target_path );
1606+ PyMem_Free (target_path );
16071607 return code ;
16081608 }
16091609 } else
@@ -1699,7 +1699,7 @@ win32_xstat_impl_w(const wchar_t *path, struct win32_stat *result,
16991699 return -1 ;
17001700
17011701 code = win32_xstat_impl_w (target_path , result , FALSE);
1702- free (target_path );
1702+ PyMem_Free (target_path );
17031703 return code ;
17041704 }
17051705 } else
@@ -3089,7 +3089,7 @@ posix_getcwd(int use_bytes)
30893089 terminating \0. If the buffer is too small, len includes
30903090 the space needed for the terminator. */
30913091 if (len >= sizeof wbuf / sizeof wbuf [0 ]) {
3092- wbuf2 = malloc (len * sizeof (wchar_t ));
3092+ wbuf2 = PyMem_RawMalloc (len * sizeof (wchar_t ));
30933093 if (wbuf2 )
30943094 len = GetCurrentDirectoryW (len , wbuf2 );
30953095 }
@@ -3100,12 +3100,12 @@ posix_getcwd(int use_bytes)
31003100 }
31013101 if (!len ) {
31023102 if (wbuf2 != wbuf )
3103- free (wbuf2 );
3103+ PyMem_RawFree (wbuf2 );
31043104 return PyErr_SetFromWindowsErr (0 );
31053105 }
31063106 resobj = PyUnicode_FromWideChar (wbuf2 , len );
31073107 if (wbuf2 != wbuf )
3108- free (wbuf2 );
3108+ PyMem_RawFree (wbuf2 );
31093109 return resobj ;
31103110 }
31113111
@@ -3289,7 +3289,7 @@ _listdir_windows_no_opendir(path_t *path, PyObject *list)
32893289 len = wcslen (path -> wide );
32903290 }
32913291 /* The +5 is so we can append "\\*.*\0" */
3292- wnamebuf = malloc ((len + 5 ) * sizeof (wchar_t ));
3292+ wnamebuf = PyMem_Malloc ((len + 5 ) * sizeof (wchar_t ));
32933293 if (!wnamebuf ) {
32943294 PyErr_NoMemory ();
32953295 goto exit ;
@@ -3410,8 +3410,7 @@ _listdir_windows_no_opendir(path_t *path, PyObject *list)
34103410 }
34113411 }
34123412 }
3413- if (wnamebuf )
3414- free (wnamebuf );
3413+ PyMem_Free (wnamebuf );
34153414
34163415 return list ;
34173416} /* end of _listdir_windows_no_opendir */
@@ -3575,7 +3574,7 @@ posix__getfullpathname(PyObject *self, PyObject *args)
35753574 Py_ARRAY_LENGTH (woutbuf ),
35763575 woutbuf , & wtemp );
35773576 if (result > Py_ARRAY_LENGTH (woutbuf )) {
3578- woutbufp = malloc (result * sizeof (wchar_t ));
3577+ woutbufp = PyMem_Malloc (result * sizeof (wchar_t ));
35793578 if (!woutbufp )
35803579 return PyErr_NoMemory ();
35813580 result = GetFullPathNameW (wpath , result , woutbufp , & wtemp );
@@ -3585,7 +3584,7 @@ posix__getfullpathname(PyObject *self, PyObject *args)
35853584 else
35863585 v = win32_error_object ("GetFullPathNameW" , po );
35873586 if (woutbufp != woutbuf )
3588- free (woutbufp );
3587+ PyMem_Free (woutbufp );
35893588 return v ;
35903589 }
35913590 /* Drop the argument parsing error as narrow strings
@@ -3655,7 +3654,7 @@ posix__getfinalpathname(PyObject *self, PyObject *args)
36553654 if (!buf_size )
36563655 return win32_error_object ("GetFinalPathNameByHandle" , po );
36573656
3658- target_path = (wchar_t * )malloc ((buf_size + 1 )* sizeof (wchar_t ));
3657+ target_path = (wchar_t * )PyMem_Malloc ((buf_size + 1 )* sizeof (wchar_t ));
36593658 if (!target_path )
36603659 return PyErr_NoMemory ();
36613660
@@ -3669,7 +3668,7 @@ posix__getfinalpathname(PyObject *self, PyObject *args)
36693668
36703669 target_path [result_length ] = 0 ;
36713670 result = PyUnicode_FromWideChar (target_path , result_length );
3672- free (target_path );
3671+ PyMem_Free (target_path );
36733672 return result ;
36743673
36753674} /* end of posix__getfinalpathname */
0 commit comments