Skip to content

Commit 935250d

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

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

Include/internal/pystate.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ PyAPI_FUNC(void) _PyRuntimeState_Fini(_PyRuntimeState *);
118118
Return NULL on success, or return an error message on failure. */
119119
PyAPI_FUNC(_PyInitError) _PyRuntime_Initialize(void);
120120

121+
PyAPI_FUNC(void) _PyRuntime_Finalize(void);
122+
123+
121124
#define _Py_CURRENTLY_FINALIZING(tstate) \
122125
(_PyRuntime.finalizing == tstate)
123126

Modules/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,8 @@ pymain_free_raw(_PyMain *pymain)
660660
orig_argc = 0;
661661
orig_argv = NULL;
662662

663+
_PyRuntime_Finalize();
664+
663665
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
664666
}
665667

0 commit comments

Comments
 (0)