bpo-40429: PyFrame_GetCode() now returns a strong reference (GH-19773)
diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c
index 39cf6e1..5e53d83 100644
--- a/Modules/_lsprof.c
+++ b/Modules/_lsprof.c
@@ -390,14 +390,19 @@
{
PyCodeObject *code = PyFrame_GetCode(frame);
ptrace_enter_call(self, (void *)code, (PyObject *)code);
+ Py_DECREF(code);
break;
}
/* the 'frame' of a called function is about to finish
(either normally or with an exception) */
case PyTrace_RETURN:
- ptrace_leave_call(self, (void *)PyFrame_GetCode(frame));
+ {
+ PyCodeObject *code = PyFrame_GetCode(frame);
+ ptrace_leave_call(self, (void *)code);
+ Py_DECREF(code);
break;
+ }
/* case PyTrace_EXCEPTION:
If the exception results in the function exiting, a