@@ -174,7 +174,7 @@ get_codec_name(const char *encoding)
174174 name_utf8 = _PyUnicode_AsString (name );
175175 if (name_utf8 == NULL )
176176 goto error ;
177- name_str = strdup (name_utf8 );
177+ name_str = _PyMem_RawStrdup (name_utf8 );
178178 Py_DECREF (name );
179179 if (name_str == NULL ) {
180180 PyErr_NoMemory ();
@@ -626,7 +626,7 @@ Py_Finalize(void)
626626
627627 /* reset file system default encoding */
628628 if (!Py_HasFileSystemDefaultEncoding && Py_FileSystemDefaultEncoding ) {
629- free ((char * )Py_FileSystemDefaultEncoding );
629+ PyMem_RawFree ((char * )Py_FileSystemDefaultEncoding );
630630 Py_FileSystemDefaultEncoding = NULL ;
631631 }
632632
@@ -1081,7 +1081,11 @@ initstdio(void)
10811081 encoding = Py_GETENV ("PYTHONIOENCODING" );
10821082 errors = NULL ;
10831083 if (encoding ) {
1084- encoding = strdup (encoding );
1084+ encoding = _PyMem_Strdup (encoding );
1085+ if (encoding == NULL ) {
1086+ PyErr_NoMemory ();
1087+ goto error ;
1088+ }
10851089 errors = strchr (encoding , ':' );
10861090 if (errors ) {
10871091 * errors = '\0' ;
@@ -1140,10 +1144,10 @@ initstdio(void)
11401144 when import.c tries to write to stderr in verbose mode. */
11411145 encoding_attr = PyObject_GetAttrString (std , "encoding" );
11421146 if (encoding_attr != NULL ) {
1143- const char * encoding ;
1144- encoding = _PyUnicode_AsString (encoding_attr );
1145- if (encoding != NULL ) {
1146- PyObject * codec_info = _PyCodec_Lookup (encoding );
1147+ const char * std_encoding ;
1148+ std_encoding = _PyUnicode_AsString (encoding_attr );
1149+ if (std_encoding != NULL ) {
1150+ PyObject * codec_info = _PyCodec_Lookup (std_encoding );
11471151 Py_XDECREF (codec_info );
11481152 }
11491153 Py_DECREF (encoding_attr );
@@ -1160,8 +1164,7 @@ initstdio(void)
11601164 status = -1 ;
11611165 }
11621166
1163- if (encoding )
1164- free (encoding );
1167+ PyMem_Free (encoding );
11651168 Py_XDECREF (bimod );
11661169 Py_XDECREF (iomod );
11671170 return status ;
0 commit comments