Skip to content

Commit f2f63b7

Browse files
committed
pythongh-109181: Fix refleak in tb_get_lineno()
PyFrame_GetCode() returns a strong reference.
1 parent 5f42a2b commit f2f63b7

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Python/traceback.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ static int
111111
tb_get_lineno(PyTracebackObject* tb) {
112112
PyFrameObject* frame = tb->tb_frame;
113113
assert(frame != NULL);
114-
return PyCode_Addr2Line(PyFrame_GetCode(frame), tb->tb_lasti);
114+
PyCodeObject *code = PyFrame_GetCode(frame);
115+
int lineno = PyCode_Addr2Line(code, tb->tb_lasti);
116+
Py_DECREF(code);
117+
return lineno;
115118
}
116119

117120
static PyObject *

0 commit comments

Comments
 (0)