From 364258afba9750c7a7af3086c6977056afed1dea Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 19 Mar 2019 14:30:23 +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/pycore_pystate.h | 2 ++ Modules/main.c | 1 + 2 files changed, 3 insertions(+) diff --git a/Include/internal/pycore_pystate.h b/Include/internal/pycore_pystate.h index 703a85b96b4e380..7c9d11aec36cfa0 100644 --- a/Include/internal/pycore_pystate.h +++ b/Include/internal/pycore_pystate.h @@ -184,6 +184,8 @@ PyAPI_FUNC(void) _PyRuntimeState_ReInitThreads(void); 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 8f7a1bfa8308b99..99396b73c650406 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -839,6 +839,7 @@ pymain_free(void) _PyPathConfig_ClearGlobal(); _Py_ClearStandardStreamEncoding(); _Py_ClearArgcArgv(); + _PyRuntime_Finalize(); }