summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2019-12-03 10:28:54 +0000
committerEric Wieser <wieser.eric@gmail.com>2019-12-03 11:42:17 +0000
commitde6e644b1853f595683cfbedb3745b24c75ce63d (patch)
treeb36f26d39d38f2952a48533c78596690920402d0 /numpy
parent33bbcf5ad1be03b68e0d9c4876a0d6dc3708e3ca (diff)
downloadnumpy-de6e644b1853f595683cfbedb3745b24c75ce63d.tar.gz
BUG: Fix refcounting in ufunc object loops
Previously `func` was leaked on both success and failure paths.
Diffstat (limited to 'numpy')
-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 6accf3065..8842176e2 100644
--- a/numpy/core/src/umath/loops.c.src
+++ b/numpy/core/src/umath/loops.c.src
@@ -575,7 +575,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);
@@ -588,6 +592,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;