]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-95045: gc untrack _lsprof.Profiler before deallocating it (GH-95315)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 27 Jul 2022 12:28:26 +0000 (05:28 -0700)
committerGitHub <noreply@github.com>
Wed, 27 Jul 2022 12:28:26 +0000 (05:28 -0700)
Automerge-Triggered-By: GH:pablogsal
(cherry picked from commit deacf391d7a1b3ab49bffa16088b3500fdb4c435)

Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Misc/NEWS.d/next/Library/2022-07-27-11-35-45.gh-issue-95045.iysT-Q.rst [new file with mode: 0644]
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 (file)
index 0000000..d4ab325
--- /dev/null
@@ -0,0 +1 @@
+Fix GC crash when deallocating ``_lsprof.Profiler`` by untracking it before calling any callbacks. Patch by Kumar Aditya.
index 8d754aa7e3ca29646d677a1e611751dc624171fe..0a6b29a969b3f7b315f1ecbef101b6f9dde64cfa 100644 (file)
@@ -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) {