-
-
Notifications
You must be signed in to change notification settings - Fork 35k
bpo-36333: Fix leaks in pymain_init and _PyPreConfig_ReadFromArgv #12389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Fix leaks in pymain_init and _PyPreConfig_ReadFromArgv. Contributed by | ||
| Stéphane Wirtel |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, I missed that in the big refactoring I did last ones. Nicely spotted ;-)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a similar leak in _PyPreConfig_Read, btharper@81e617d I didn't see any more cases grepping for setlocale calls |
||
| } | ||
| _PyPreConfig_Clear(&save_config); | ||
| Py_UTF8Mode = init_utf8_mode ; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please write a separated PR to this change. I don't know well this code, so I'm not sure how xidregistry is supposed to be used. |
||
| } | ||
|
|
||
| PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not the right place to cleanup things. I redesigned deeply Py_Main() to replace exit() call in mutliple layers of function calls, far from Py_Main(), with _PyInitError which allows to give back the control flow to Py_Main(). I did that to be able to cleanup Python properly.