8000 gh-92036: Fix gc_fini_untrack() (GH-92037) · python/cpython@178a238 · GitHub
[go: up one dir, main page]

Skip to content
  • Insights
  • Commit 178a238

    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 <vstinner@python.org>
    1 parent 28eea73 commit 178a238

    File tree

    2 files changed

    +11
    -0
    lines changed

    2 files changed

    +11
    -0
    lines changed
    Lines changed: 5 additions & 0 deletions
    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

    Lines changed: 6 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -2170,6 +2170,12 @@ gc_fini_untrack(PyGC_Head *list)
    21702170
    for (gc = GC_NEXT(list); gc != list; gc = GC_NEXT(list)) {
    21712171
    PyObject *op = FROM_GC(gc);
    21722172
    _PyObject_GC_UNTRACK(op);
    2173+
    // gh-92036: If a deallocator function expect the object to be tracked
    2174+
    // by the GC (ex: func_dealloc()), it can crash if called on an object
    2175+
    // which is no longer tracked by the GC. Leak one strong reference on
    2176+
    // purpose so the object is never deleted and its deallocator is not
    2177+
    // called.
    2178+
    Py_INCREF(op);
    21732179
    }
    21742180
    }
    21752181

    0 commit comments

    Comments
     (0)
    0