summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2019-12-03 09:06:18 -0800
committerGitHub <noreply@github.com>2019-12-03 09:06:18 -0800
commite3abc15fd37213780b683e5f7ba93f40ed3686dd (patch)
treed768b7b3f52de9ab999fced829e928b877bb306f
parent56f5a9a55382884ce151a66ae8afe31cd4be4b38 (diff)
parentde6e644b1853f595683cfbedb3745b24c75ce63d (diff)
downloadnumpy-e3abc15fd37213780b683e5f7ba93f40ed3686dd.tar.gz
Merge pull request #15038 from eric-wieser/fix-leak
BUG: Fix refcounting in ufunc object loops
-rw-r--r--numpy/core/src/umath/loops.c.src7
1 files changed, 6 insertions, 1 deletions
diff --git a/numpy/core/src/umath/loops.c.src b/numpy/core/src/umath/loops.c.src
index f84d74efe..1931cd100 100644
--- a/numpy/core/src/umath/loops.c.src
+++ b/numpy/core/src/umath/loops.c.src
@@ -384,7 +384,11 @@ PyUFunc_O_O_method(char **args, npy_intp *dimensions, npy_intp *steps, void *fun
PyObject **out = (PyObject **)op1;
PyObject *ret, *func;
func = PyObject_GetAttrString(in1 ? in1 : Py_None, meth);
- if (func == NULL || !PyCallable_Check(func)) {
+ if (func != NULL && !PyCallable_Check(func)) {
+ Py_DECREF(func);
+ func = NULL;
+ }
+ if (func == NULL) {
PyObject *exc, *val, *tb;
PyTypeObject *type = in1 ? Py_TYPE(in1) : Py_TYPE(Py_None);
PyErr_Fetch(&exc, &val, &tb);
@@ -397,6 +401,7 @@ PyUFunc_O_O_method(char **args, npy_intp *dimensions, npy_intp *steps, void *fun
return;
}
ret = PyObject_Call(func, tup, NULL);
+ Py_DECREF(func);
if (ret == NULL) {
Py_DECREF(tup);
return;