Skip to content

Commit f5f336a

Browse files
authored
bpo-36356: pymain_free() calls _PyRuntime_Finalize() (GH-12435)
Ensure that _PyRuntime_Finalize() is always call. This change fix a few memory leaks when running "python3 -V".
1 parent fecc4f2 commit f5f336a

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

Include/internal/pycore_pystate.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ PyAPI_FUNC(void) _PyRuntimeState_ReInitThreads(void);
184184
Return NULL on success, or return an error message on failure. */
185185
PyAPI_FUNC(_PyInitError) _PyRuntime_Initialize(void);
186186

187+
PyAPI_FUNC(void) _PyRuntime_Finalize(void);
188+
187189
#define _Py_CURRENTLY_FINALIZING(tstate) \
188190
(_PyRuntime.finalizing == tstate)
189191

Modules/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,7 @@ pymain_free(void)
839839
_PyPathConfig_ClearGlobal();
840840
_Py_ClearStandardStreamEncoding();
841841
_Py_ClearArgcArgv();
842+
_PyRuntime_Finalize();
842843
}
843844

844845

0 commit comments

Comments
 (0)