Skip to content

Commit 8222ad0

Browse files
[3.11] [3.12] gh-109181: Fix refleak in tb_get_lineno() (GH-111948) (#111951)
[3.12] gh-109181: Fix refleak in tb_get_lineno() (GH-111948) PyFrame_GetCode() returns a strong reference. (cherry picked from commit 4b0c875) Co-authored-by: Victor Stinner <[email protected]>
1 parent 7b84451 commit 8222ad0

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
@@ -115,7 +115,10 @@ static int
115115
tb_get_lineno(PyTracebackObject* tb) {
116116
PyFrameObject* frame = tb->tb_frame;
117117
assert(frame != NULL);
118-
return PyCode_Addr2Line(PyFrame_GetCode(frame), tb->tb_lasti);
118+
PyCodeObject *code = PyFrame_GetCode(frame);
119+
int lineno = PyCode_Addr2Line(code, tb->tb_lasti);
120+
Py_DECREF(code);
121+
return lineno;
119122
}
120123

121124
static PyObject *

0 commit comments

Comments
 (0)