summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-11-10 13:32:02 (GMT)
committerGitHub <noreply@github.com>2023-11-10 13:32:02 (GMT)
commit8222ad01fe5e802649f0a1bd30d26d4623533c51 (patch)
tree9efe76ac3aea1d67986fa07b69ced78a4f3b0e96 /Python
parent7b8445109d7dd8b319f5239ca013e83938579b4c (diff)
downloadcpython-8222ad01fe5e802649f0a1bd30d26d4623533c51.zip
cpython-8222ad01fe5e802649f0a1bd30d26d4623533c51.tar.gz
cpython-8222ad01fe5e802649f0a1bd30d26d4623533c51.tar.bz2
[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 4b0c875d91727440251a8427a80d8515e39d18cd) Co-authored-by: Victor Stinner <vstinner@python.org>
Diffstat (limited to 'Python')
-rw-r--r--Python/traceback.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/Python/traceback.c b/Python/traceback.c
index 664a73f..722f007 100644
--- a/Python/traceback.c
+++ b/Python/traceback.c
@@ -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 *