@@ -1274,7 +1274,12 @@ _Py_open_impl(const char *pathname, int flags, int gil_held)
12741274#endif
12751275
12761276 if (gil_held ) {
1277- if (PySys_Audit ("open" , "sOi" , pathname , Py_None , flags ) < 0 ) {
1277+ PyObject * pathname_obj = PyUnicode_DecodeFSDefault (pathname );
1278+ if (pathname_obj == NULL ) {
1279+ return -1 ;
1280+ }
1281+ if (PySys_Audit ("open" , "OOi" , pathname_obj , Py_None , flags ) < 0 ) {
1282+ Py_DECREF (pathname_obj );
12781283 return -1 ;
12791284 }
12801285
@@ -1284,12 +1289,16 @@ _Py_open_impl(const char *pathname, int flags, int gil_held)
12841289 Py_END_ALLOW_THREADS
12851290 } while (fd < 0
12861291 && errno == EINTR && !(async_err = PyErr_CheckSignals ()));
1287- if (async_err )
1292+ if (async_err ) {
1293+ Py_DECREF (pathname_obj );
12881294 return -1 ;
1295+ }
12891296 if (fd < 0 ) {
1290- PyErr_SetFromErrnoWithFilename (PyExc_OSError , pathname );
1297+ PyErr_SetFromErrnoWithFilenameObjects (PyExc_OSError , pathname_obj , NULL );
1298+ Py_DECREF (pathname_obj );
12911299 return -1 ;
12921300 }
1301+ Py_DECREF (pathname_obj );
12931302 }
12941303 else {
12951304 fd = open (pathname , flags );
@@ -1385,9 +1394,15 @@ _Py_wfopen(const wchar_t *path, const wchar_t *mode)
13851394FILE *
13861395_Py_fopen (const char * pathname , const char * mode )
13871396{
1388- if (PySys_Audit ("open" , "ssi" , pathname , mode , 0 ) < 0 ) {
1397+ PyObject * pathname_obj = PyUnicode_DecodeFSDefault (pathname );
1398+ if (pathname_obj == NULL ) {
1399+ return NULL ;
1400+ }
1401+ if (PySys_Audit ("open" , "Osi" , pathname_obj , mode , 0 ) < 0 ) {
1402+ Py_DECREF (pathname_obj );
13891403 return NULL ;
13901404 }
1405+ Py_DECREF (pathname_obj );
13911406
13921407 FILE * f = fopen (pathname , mode );
13931408 if (f == NULL )
0 commit comments