diff options
author | Victor Stinner <vstinner@python.org> | 2021-08-30 13:24:39 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-30 13:24:39 (GMT) |
commit | fe997e1a67835a929705c8c305d41c4d7dd326e3 (patch) | |
tree | 1cd00b08faadc55d36144628a4ba6af4f5c606cb /Python | |
parent | 52bdda50d7b79e1ad7e57967850beff64c3ede92 (diff) | |
download | cpython-fe997e1a67835a929705c8c305d41c4d7dd326e3.zip cpython-fe997e1a67835a929705c8c305d41c4d7dd326e3.tar.gz cpython-fe997e1a67835a929705c8c305d41c4d7dd326e3.tar.bz2 |
bpo-44449: faulthandler don't modify frame refcnt (GH-27850)
Fix a crash in the signal handler of the faulthandler module: no
longer modify the reference count of frame objects.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/traceback.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/Python/traceback.c b/Python/traceback.c index f7dc5ad..88ffc01 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -796,7 +796,10 @@ dump_traceback(int fd, PyThreadState *tstate, int write_header) PUTS(fd, "Stack (most recent call first):\n"); } - frame = PyThreadState_GetFrame(tstate); + // Use a borrowed reference. Avoid Py_INCREF/Py_DECREF, since this function + // can be called in a signal handler by the faulthandler module which must + // not modify Python objects. + frame = tstate->frame; if (frame == NULL) { PUTS(fd, "<no Python frame>\n"); return; @@ -805,17 +808,14 @@ dump_traceback(int fd, PyThreadState *tstate, int write_header) depth = 0; while (1) { if (MAX_FRAME_DEPTH <= depth) { - Py_DECREF(frame); PUTS(fd, " ...\n"); break; } if (!PyFrame_Check(frame)) { - Py_DECREF(frame); break; } dump_frame(fd, frame); - PyFrameObject *back = PyFrame_GetBack(frame); - Py_DECREF(frame); + PyFrameObject *back = frame->f_back; if (back == NULL) { break; |