From: Victor Stinner Date: Fri, 10 Nov 2023 13:07:45 +0000 (+0100) Subject: [3.12] gh-109181: Fix refleak in tb_get_lineno() (#111948) X-Git-Tag: v3.12.1~147 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4b0c875d91727440251a8427a80d8515e39d18cd;p=thirdparty%2FPython%2Fcpython.git [3.12] gh-109181: Fix refleak in tb_get_lineno() (#111948) PyFrame_GetCode() returns a strong reference. --- diff --git a/Python/traceback.c b/Python/traceback.c index b627b06df7e6..fdaf19d37074 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 *