From 4b0c875d91727440251a8427a80d8515e39d18cd Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 10 Nov 2023 14:07:45 +0100 Subject: [3.12] gh-109181: Fix refleak in tb_get_lineno() (#111948) PyFrame_GetCode() returns a strong reference. --- Python/traceback.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Python/traceback.c b/Python/traceback.c index b627b06..fdaf19d 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -111,7 +111,10 @@ static int tb_get_lineno(PyTracebackObject* tb) { PyFrameObject* frame = tb->tb_frame; assert(frame != NULL); - return PyCode_Addr2Line(PyFrame_GetCode(frame), tb->tb_lasti); + PyCodeObject *code = PyFrame_GetCode(frame); + int lineno = PyCode_Addr2Line(code, tb->tb_lasti); + Py_DECREF(code); + return lineno; } static PyObject * -- cgit v0.12