@@ -2483,25 +2483,28 @@ sys_remote_exec_impl(PyObject *module, int pid, PyObject *script)
24832483{
24842484 PyObject * path ;
24852485 const char * debugger_script_path ;
2486- #ifdef MS_WINDOWS
2487- if (PyUnicode_FSDecoder (script , & path ) < 0 ) {
2486+
2487+ if (PyUnicode_FSConverter (script , & path ) < 0 ) {
24882488 return NULL ;
24892489 }
2490- debugger_script_path = PyUnicode_AsUTF8 (path );
2491- if (debugger_script_path == NULL ) {
2490+ debugger_script_path = PyBytes_AS_STRING (path );
2491+ #ifdef MS_WINDOWS
2492+ PyObject * unicode_path ;
2493+ if (PyUnicode_FSDecoder (path , & unicode_path ) < 0 ) {
24922494 Py_DECREF (path );
24932495 return NULL ;
24942496 }
24952497 // Use UTF-16 (wide char) version of the path for permission checks
2496- wchar_t * debugger_script_path_w = PyUnicode_AsWideCharString (path , NULL );
2498+ wchar_t * debugger_script_path_w = PyUnicode_AsWideCharString (unicode_path , NULL );
2499+ Py_DECREF (unicode_path );
24972500 if (debugger_script_path_w == NULL ) {
24982501 Py_DECREF (path );
24992502 return NULL ;
25002503 }
25012504 DWORD attr = GetFileAttributesW (debugger_script_path_w );
2502- PyMem_Free (debugger_script_path_w );
25032505 if (attr == INVALID_FILE_ATTRIBUTES ) {
25042506 DWORD err = GetLastError ();
2507+ PyMem_Free (debugger_script_path_w );
25052508 if (err == ERROR_FILE_NOT_FOUND || err == ERROR_PATH_NOT_FOUND ) {
25062509 PyErr_SetString (PyExc_FileNotFoundError , "Script file does not exist" );
25072510 }
@@ -2514,12 +2517,8 @@ sys_remote_exec_impl(PyObject *module, int pid, PyObject *script)
25142517 Py_DECREF (path );
25152518 return NULL ;
25162519 }
2520+ PyMem_Free (debugger_script_path_w );
25172521#else // MS_WINDOWS
2518- if (PyUnicode_FSConverter (script , & path ) < 0 ) {
2519- return NULL ;
2520- }
2521- debugger_script_path = PyBytes_AS_STRING (path );
2522-
25232522 if (access (debugger_script_path , F_OK | R_OK ) != 0 ) {
25242523 switch (errno ) {
25252524 case ENOENT :
0 commit comments