summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>2022-07-27 12:03:50 (GMT)
committerGitHub <noreply@github.com>2022-07-27 12:03:50 (GMT)
commitdeacf391d7a1b3ab49bffa16088b3500fdb4c435 (patch)
tree71565f95d0ca75582cb559cf8ac51d7bf9a51da8
parent78eb3f79eae772f7a5cdbb2cc02c12b05bd88305 (diff)
downloadcpython-deacf391d7a1b3ab49bffa16088b3500fdb4c435.zip
cpython-deacf391d7a1b3ab49bffa16088b3500fdb4c435.tar.gz
cpython-deacf391d7a1b3ab49bffa16088b3500fdb4c435.tar.bz2
GH-95045: gc untrack _lsprof.Profiler before deallocating it (GH-95315)
Automerge-Triggered-By: GH:pablogsal
-rw-r--r--Misc/NEWS.d/next/Library/2022-07-27-11-35-45.gh-issue-95045.iysT-Q.rst1
-rw-r--r--Modules/_lsprof.c1
2 files changed, 2 insertions, 0 deletions
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 0000000..d4ab325
--- /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 0e8432f..a0e262b 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) {