From de3e9b3e9cf2ceff834c0b0b7373b635e44a480a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 19 Mar 2019 14:35:15 +0100 Subject: [PATCH] bpo-36356: pymain_free() calls _PyRuntime_Finalize() Ensure that _PyRuntime_Finalize() is always call. This change fix a few memory leaks when running "python3 -V". --- Include/internal/pystate.h | 3 +++ Modules/main.c | 2 ++ 2 files changed, 5 insertions(+) diff --git a/Include/internal/pystate.h b/Include/internal/pystate.h index 721d34fa4c1962..5891339b543482 100644 --- a/Include/internal/pystate.h +++ b/Include/internal/pystate.h @@ -118,6 +118,9 @@ PyAPI_FUNC(void) _PyRuntimeState_Fini(_PyRuntimeState *); Return NULL on success, or return an error message on failure. */ PyAPI_FUNC(_PyInitError) _PyRuntime_Initialize(void); +PyAPI_FUNC(void) _PyRuntime_Finalize(void); + + #define _Py_CURRENTLY_FINALIZING(tstate) \ (_PyRuntime.finalizing == tstate) diff --git a/Modules/main.c b/Modules/main.c index a745381109d377..f94689496a38fc 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -660,6 +660,8 @@ pymain_free_raw(_PyMain *pymain) orig_argc = 0; orig_argv = NULL; + _PyRuntime_Finalize(); + PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); }