diff --git a/Modules/main.c b/Modules/main.c index 5c7f7e45673a122..50fecc9103d926e 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -888,13 +888,13 @@ pymain_main(_PyArgv *args) PyInterpreterState *interp; err = pymain_init(args, &interp); if (_Py_INIT_FAILED(err)) { - _Py_ExitInitError(err); + goto exit_init_error; } int exitcode = 0; err = pymain_run_python(interp, &exitcode); if (_Py_INIT_FAILED(err)) { - _Py_ExitInitError(err); + goto exit_init_error; } if (Py_FinalizeEx() < 0) { @@ -910,6 +910,10 @@ pymain_main(_PyArgv *args) } return exitcode; + +exit_init_error: + pymain_free(); + _Py_ExitInitError(err); } diff --git a/Python/pathconfig.c b/Python/pathconfig.c index fb2d19e2797a7d2..0ee87c42525f49b 100644 --- a/Python/pathconfig.c +++ b/Python/pathconfig.c @@ -149,7 +149,12 @@ _PyPathConfig_SetGlobal(const _PyPathConfig *config) void _PyPathConfig_ClearGlobal(void) { + PyMemAllocatorEx old_alloc; + _PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc); + _PyPathConfig_Clear(&_Py_path_config); + + PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); } diff --git a/Python/preconfig.c b/Python/preconfig.c index a86ece57cfced93..1efc7ee5c56ed1a 100644 --- a/Python/preconfig.c +++ b/Python/preconfig.c @@ -758,6 +758,7 @@ _PyPreConfig_ReadFromArgv(_PyPreConfig *config, const _PyArgv *args) done: if (init_ctype_locale != NULL) { setlocale(LC_CTYPE, init_ctype_locale); + PyMem_RawFree(init_ctype_locale); } _PyPreConfig_Clear(&save_config); Py_UTF8Mode = init_utf8_mode ;