Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f84c51e

Browse files
gh-92036: Fix gc_fini_untrack() (GH-92037)
Fix a crash in subinterpreters related to the garbage collector. When a subinterpreter is deleted, untrack all objects tracked by its GC. To prevent a crash in deallocator functions expecting objects to be tracked by the GC, leak a strong reference to these objects on purpose, so they are never deleted and their deallocator functions are not called. (cherry picked from commit 1424336) Co-authored-by: Victor Stinner <[email protected]>
1 parent 524d275 commit f84c51e

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Fix a crash in subinterpreters related to the garbage collector. When a
2+
subinterpreter is deleted, untrack all objects tracked by its GC. To prevent a
3+
crash in deallocator functions expecting objects to be tracked by the GC, leak
4+
a strong reference to these objects on purpose, so they are never deleted and
5+
their deallocator functions are not called. Patch by Victor Stinner.

Modules/gcmodule.c

+6
Original file line numberDiff line numberDiff line change
@@ -2157,6 +2157,12 @@ gc_fini_untrack(PyGC_Head *list)
21572157
for (gc = GC_NEXT(list); gc != list; gc = GC_NEXT(list)) {
21582158
PyObject *op = FROM_GC(gc);
21592159
_PyObject_GC_UNTRACK(op);
2160+
// gh-92036: If a deallocator function expect the object to be tracked
2161+
// by the GC (ex: func_dealloc()), it can crash if called on an object
2162+
// which is no longer tracked by the GC. Leak one strong reference on
2163+
// purpose so the object is never deleted and its deallocator is not
2164+
// called.
2165+
Py_INCREF(op);
21602166
}
21612167
}
21622168

0 commit comments

Comments
 (0)