Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions Modules/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ pymain_init(const _PyArgv *args, PyInterpreterState **interp_p)

err = config_read_write(config, args, preconfig);
if (_Py_INIT_FAILED(err)) {
_PyRuntimeState_Fini(&_PyRuntime);

Copy link
Copy Markdown
Member

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.

goto done;
}

Expand Down
1 change: 1 addition & 0 deletions Python/preconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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 ;-)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 ;
Expand Down
5 changes: 5 additions & 0 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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);
}

Expand Down