Repository navigation
gh-122697: Fix free-threading memory leaks at shutdown #122703
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 5 commits
c9d7132
04f9582
28d6768
dcb709d
7fc200b
05db2d8
44db4e0
33cc40c
312f860
70e25f5
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 @@ | ||
| Fixed memory leaks at interpreter shutdown in the free-threaded build, and | ||
| also reporting of leaked memory blocks via ``-X showrefcount``. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1109,9 +1109,12 @@ free_delayed(uintptr_t ptr) | |
| #ifndef Py_GIL_DISABLED | ||
| free_work_item(ptr); | ||
| #else | ||
| if (_PyRuntime.stoptheworld.world_stopped) { | ||
| // Free immediately if the world is stopped, including during | ||
| // interpreter shutdown. | ||
| PyInterpreterState *interp = _PyInterpreterState_GET(); | ||
| if (_PyInterpreterState_GetFinalizing(interp) != NULL || | ||
| interp->stoptheworld.world_stopped) | ||
| { | ||
| // Free immediately during interpreter shutdown or if the world is | ||
|
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. runtime shutdown would be better instead of interpreter shutdown?
Contributor
Author
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. Thanks, this should be interpreter shutdown. That's why the refleak buildbots had failures. |
||
| // stopped. | ||
| free_work_item(ptr); | ||
| return; | ||
| } | ||
|
|
@@ -1474,6 +1477,8 @@ _PyInterpreterState_FinalizeAllocatedBlocks(PyInterpreterState *interp) | |
| { | ||
| #ifdef WITH_MIMALLOC | ||
| if (_PyMem_MimallocEnabled()) { | ||
| Py_ssize_t leaked = _PyInterpreterState_GetAllocatedBlocks(interp); | ||
| interp->runtime->obmalloc.interpreter_leaks += leaked; | ||
| return; | ||
| } | ||
| #endif | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.