diff --git a/Misc/NEWS.d/next/Library/2022-07-27-11-35-45.gh-issue-95045.iysT-Q.rst b/Misc/NEWS.d/next/Library/2022-07-27-11-35-45.gh-issue-95045.iysT-Q.rst new file mode 100644 index 00000000000..d4ab325e036 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-07-27-11-35-45.gh-issue-95045.iysT-Q.rst @@ -0,0 +1 @@ +Fix GC crash when deallocating ``_lsprof.Profiler`` by untracking it before calling any callbacks. Patch by Kumar Aditya. diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c index 0e8432fda01..a0e262bdac2 100644 --- a/Modules/_lsprof.c +++ b/Modules/_lsprof.c @@ -747,6 +747,7 @@ profiler_traverse(ProfilerObject *op, visitproc visit, void *arg) static void profiler_dealloc(ProfilerObject *op) { + PyObject_GC_UnTrack(op); if (op->flags & POF_ENABLED) { PyThreadState *tstate = _PyThreadState_GET(); if (_PyEval_SetProfile(tstate, NULL, NULL) < 0) {