bpo-34190: Fix reference leak in call_function() (GH-8413) (GH-8418)
(cherry picked from commit 147d95511f59cfdd2d522f9d736f2335457bae20)
Co-authored-by: jdemeyer <jdemeyer@cage.ugent.be>
diff --git a/Python/ceval.c b/Python/ceval.c
index 600147b..0d1519b 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4565,12 +4565,15 @@
profiling. */
PyObject *self = stack[0];
func = Py_TYPE(func)->tp_descr_get(func, self, (PyObject*)Py_TYPE(self));
- if (func == NULL) {
- return NULL;
+ if (func != NULL) {
+ C_TRACE(x, _PyCFunction_FastCallKeywords(func,
+ stack+1, nargs-1,
+ kwnames));
+ Py_DECREF(func);
}
- C_TRACE(x, _PyCFunction_FastCallKeywords(func, stack+1, nargs-1,
- kwnames));
- Py_DECREF(func);
+ else {
+ x = NULL;
+ }
}
else {
x = _PyMethodDescr_FastCallKeywords(func, stack, nargs, kwnames);