[Python-checkins] GH-95045: gc untrack _lsprof.Profiler before deallocating it (GH-95315)

miss-islington webhook-mailer at python.org
Wed Jul 27 08:28:33 EDT 2022


https://github.com/python/cpython/commit/657efca298bac3a4fcc66e917a464e4a6764f0d3
commit: 657efca298bac3a4fcc66e917a464e4a6764f0d3
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-07-27T05:28:26-07:00
summary:

GH-95045: gc untrack _lsprof.Profiler before deallocating it (GH-95315)


Automerge-Triggered-By: GH:pablogsal
(cherry picked from commit deacf391d7a1b3ab49bffa16088b3500fdb4c435)

Co-authored-by: Kumar Aditya <59607654+kumaraditya303 at users.noreply.github.com>

files:
A Misc/NEWS.d/next/Library/2022-07-27-11-35-45.gh-issue-95045.iysT-Q.rst
M Modules/_lsprof.c

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 0000000000000..d4ab325e03658
--- /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 8d754aa7e3ca2..0a6b29a969b3f 100644
--- a/Modules/_lsprof.c
+++ b/Modules/_lsprof.c
@@ -741,6 +741,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) {



More information about the Python-checkins mailing list