[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 4b0c875d91)

Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
Miss Islington (bot) 2023-11-10 14:32:02 +01:00 committed by GitHub
parent 7b8445109d
commit 8222ad01fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -115,7 +115,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 *