@@ -245,9 +245,9 @@ getpythonregpath(HKEY keyBase, int skipcore)
245245 /* Tried to use sysget("winver") but here is too early :-( */
246246 versionLen = strlen (PyWin_DLLVersionString );
247247 /* Space for all the chars, plus one \0 */
248- keyBuf = keyBufPtr = malloc (sizeof (keyPrefix ) +
249- sizeof (WCHAR )* (versionLen - 1 ) +
250- sizeof (keySuffix ));
248+ keyBuf = keyBufPtr = PyMem_RawMalloc (sizeof (keyPrefix ) +
249+ sizeof (WCHAR )* (versionLen - 1 ) +
250+ sizeof (keySuffix ));
251251 if (keyBuf == NULL ) goto done ;
252252
253253 memcpy (keyBufPtr , keyPrefix , sizeof (keyPrefix )- sizeof (WCHAR ));
@@ -271,7 +271,7 @@ getpythonregpath(HKEY keyBase, int skipcore)
271271 /* Allocate a temp array of char buffers, so we only need to loop
272272 reading the registry once
273273 */
274- ppPaths = malloc ( sizeof (WCHAR * ) * numKeys );
274+ ppPaths = PyMem_RawMalloc ( sizeof (WCHAR * ) * numKeys );
275275 if (ppPaths == NULL ) goto done ;
276276 memset (ppPaths , 0 , sizeof (WCHAR * ) * numKeys );
277277 /* Loop over all subkeys, allocating a temp sub-buffer. */
@@ -293,7 +293,7 @@ getpythonregpath(HKEY keyBase, int skipcore)
293293 /* Find the value of the buffer size, malloc, then read it */
294294 RegQueryValueExW (subKey , NULL , 0 , NULL , NULL , & reqdSize );
295295 if (reqdSize ) {
296- ppPaths [index ] = malloc (reqdSize );
296+ ppPaths [index ] = PyMem_RawMalloc (reqdSize );
297297 if (ppPaths [index ]) {
298298 RegQueryValueExW (subKey , NULL , 0 , NULL ,
299299 (LPBYTE )ppPaths [index ],
@@ -308,7 +308,7 @@ getpythonregpath(HKEY keyBase, int skipcore)
308308 if (dataSize == 0 ) goto done ;
309309
310310 /* original datasize from RegQueryInfo doesn't include the \0 */
311- dataBuf = malloc ((dataSize + 1 ) * sizeof (WCHAR ));
311+ dataBuf = PyMem_RawMalloc ((dataSize + 1 ) * sizeof (WCHAR ));
312312 if (dataBuf ) {
313313 WCHAR * szCur = dataBuf ;
314314 DWORD reqdSize = dataSize ;
@@ -346,14 +346,13 @@ getpythonregpath(HKEY keyBase, int skipcore)
346346done :
347347 /* Loop freeing my temp buffers */
348348 if (ppPaths ) {
349- for (index = 0 ;index < numKeys ;index ++ )
350- if ( ppPaths [ index ]) free (ppPaths [index ]);
351- free (ppPaths );
349+ for (index = 0 ; index < numKeys ; index ++ )
350+ PyMem_RawFree (ppPaths [index ]);
351+ PyMem_RawFree (ppPaths );
352352 }
353353 if (newKey )
354354 RegCloseKey (newKey );
355- if (keyBuf )
356- free (keyBuf );
355+ PyMem_RawFree (keyBuf );
357356 return retval ;
358357}
359358#endif /* Py_ENABLE_SHARED */
@@ -616,7 +615,7 @@ calculate_path(void)
616615 if (envpath != NULL )
617616 bufsz += wcslen (envpath ) + 1 ;
618617
619- module_search_path = buf = malloc (bufsz * sizeof (wchar_t ));
618+ module_search_path = buf = PyMem_RawMalloc (bufsz * sizeof (wchar_t ));
620619 if (buf == NULL ) {
621620 /* We can't exit, so print a warning and limp along */
622621 fprintf (stderr , "Can't malloc dynamic PYTHONPATH.\n" );
@@ -629,10 +628,8 @@ calculate_path(void)
629628 module_search_path = PYTHONPATH ;
630629 }
631630#ifdef MS_WINDOWS
632- if (machinepath )
633- free (machinepath );
634- if (userpath )
635- free (userpath );
631+ PyMem_RawFree (machinepath );
632+ PyMem_RawFree (userpath );
636633#endif /* MS_WINDOWS */
637634 return ;
638635 }
@@ -652,13 +649,13 @@ calculate_path(void)
652649 wcscpy (buf , userpath );
653650 buf = wcschr (buf , L'\0' );
654651 * buf ++ = DELIM ;
655- free (userpath );
652+ PyMem_RawFree (userpath );
656653 }
657654 if (machinepath ) {
658655 wcscpy (buf , machinepath );
659656 buf = wcschr (buf , L'\0' );
660657 * buf ++ = DELIM ;
661- free (machinepath );
658+ PyMem_RawFree (machinepath );
662659 }
663660 if (pythonhome == NULL ) {
664661 if (!skipdefault ) {
@@ -745,18 +742,18 @@ void
745742Py_SetPath (const wchar_t * path )
746743{
747744 if (module_search_path != NULL ) {
748- free (module_search_path );
745+ PyMem_RawFree (module_search_path );
749746 module_search_path = NULL ;
750747 }
751748 if (path != NULL ) {
752749 extern wchar_t * Py_GetProgramName (void );
753750 wchar_t * prog = Py_GetProgramName ();
754751 wcsncpy (progpath , prog , MAXPATHLEN );
755752 prefix [0 ] = L'\0' ;
756- module_search_path = malloc ((wcslen (path ) + 1 ) * sizeof (wchar_t ));
753+ module_search_path = PyMem_RawMalloc ((wcslen (path ) + 1 ) * sizeof (wchar_t ));
757754 if (module_search_path != NULL )
758755 wcscpy (module_search_path , path );
759- }
756+ }
760757}
761758
762759wchar_t *
0 commit comments