From 99da539d1c50d84c6b96f40e77cd09c19ac9c279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Wirtel?= Date: Mon, 18 Mar 2019 00:48:42 +0100 Subject: [PATCH] bpo-36333: Fix leaks in pymain_init and _PyPreConfig_ReadFromArgv --- .../2019-03-18-00-48-10.bpo-36333.EVoGFR.rst | 2 ++ Modules/main.c | 1 + Python/preconfig.c | 1 + Python/pystate.c | 5 +++++ 4 files changed, 9 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2019-03-18-00-48-10.bpo-36333.EVoGFR.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-03-18-00-48-10.bpo-36333.EVoGFR.rst b/Misc/NEWS.d/next/Core and Builtins/2019-03-18-00-48-10.bpo-36333.EVoGFR.rst new file mode 100644 index 000000000000000..0f8eb000265a6f3 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2019-03-18-00-48-10.bpo-36333.EVoGFR.rst @@ -0,0 +1,2 @@ +Fix leaks in pymain_init and _PyPreConfig_ReadFromArgv. Contributed by +Stéphane Wirtel diff --git a/Modules/main.c b/Modules/main.c index 5c7f7e45673a122..1b0ad9db9b0aba8 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -363,6 +363,7 @@ pymain_init(const _PyArgv *args, PyInterpreterState **interp_p) err = config_read_write(config, args, preconfig); if (_Py_INIT_FAILED(err)) { + _PyRuntimeState_Fini(&_PyRuntime); goto done; } 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 ; diff --git a/Python/pystate.c b/Python/pystate.c index 6a2dc102ecfebc6..36566b767155b31 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -92,6 +92,11 @@ _PyRuntimeState_Fini(_PyRuntimeState *runtime) runtime->interpreters.mutex = NULL; } + if (runtime->xidregistry.mutex != NULL) { + PyThread_free_lock(runtime->xidregistry.mutex); + runtime->xidregistry.mutex = NULL; + } + PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); }