Skip to content

Commit b7e3a11

Browse files
acquire critical section around tb_next
1 parent 0408481 commit b7e3a11

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Python/traceback.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,17 @@ traceback_tb_next_set_impl(PyTracebackObject *self, PyObject *value)
167167

168168
/* Check for loops */
169169
PyTracebackObject *cursor = (PyTracebackObject *)value;
170+
Py_XINCREF(cursor);
170171
while (cursor) {
171172
if (cursor == self) {
172173
PyErr_Format(PyExc_ValueError, "traceback loop detected");
174+
Py_DECREF(cursor);
173175
return -1;
174176
}
175-
cursor = cursor->tb_next;
177+
Py_BEGIN_CRITICAL_SECTION(cursor);
178+
Py_XINCREF(cursor->tb_next);
179+
Py_SETREF(cursor, cursor->tb_next);
180+
Py_END_CRITICAL_SECTION();
176181
}
177182

178183
Py_XSETREF(self->tb_next, (PyTracebackObject *)Py_XNewRef(value));

0 commit comments

Comments
 (0)