]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-109181: Fix refleak in tb_get_lineno() (#111948)
authorVictor Stinner <vstinner@python.org>
Fri, 10 Nov 2023 13:07:45 +0000 (14:07 +0100)
committerGitHub <noreply@github.com>
Fri, 10 Nov 2023 13:07:45 +0000 (14:07 +0100)
PyFrame_GetCode() returns a strong reference.

Python/traceback.c

index b627b06df7e6a77c56236b73691bac3dc2636880..fdaf19d37074dd6d4e2ce063e1981aa1a1c5ff93 100644 (file)
@@ -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 *