mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
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.
(cherry picked from commit fe997e1a67)
Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
parent
0c5e0aa73f
commit
720aef48b5
2 changed files with 7 additions and 5 deletions
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix a crash in the signal handler of the :mod:`faulthandler` module: no
|
||||||
|
longer modify the reference count of frame objects. Patch by Victor Stinner.
|
||||||
|
|
@ -799,7 +799,10 @@ dump_traceback(int fd, PyThreadState *tstate, int write_header)
|
||||||
PUTS(fd, "Stack (most recent call first):\n");
|
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) {
|
if (frame == NULL) {
|
||||||
PUTS(fd, "<no Python frame>\n");
|
PUTS(fd, "<no Python frame>\n");
|
||||||
return;
|
return;
|
||||||
|
|
@ -808,17 +811,14 @@ dump_traceback(int fd, PyThreadState *tstate, int write_header)
|
||||||
depth = 0;
|
depth = 0;
|
||||||
while (1) {
|
while (1) {
|
||||||
if (MAX_FRAME_DEPTH <= depth) {
|
if (MAX_FRAME_DEPTH <= depth) {
|
||||||
Py_DECREF(frame);
|
|
||||||
PUTS(fd, " ...\n");
|
PUTS(fd, " ...\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!PyFrame_Check(frame)) {
|
if (!PyFrame_Check(frame)) {
|
||||||
Py_DECREF(frame);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
dump_frame(fd, frame);
|
dump_frame(fd, frame);
|
||||||
PyFrameObject *back = PyFrame_GetBack(frame);
|
PyFrameObject *back = frame->f_back;
|
||||||
Py_DECREF(frame);
|
|
||||||
|
|
||||||
if (back == NULL) {
|
if (back == NULL) {
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue