diff options
| author | warren <warren.weckesser@gmail.com> | 2021-09-23 09:06:21 -0400 |
|---|---|---|
| committer | warren <warren.weckesser@gmail.com> | 2021-09-23 09:06:21 -0400 |
| commit | ec6b1aef8d81a06385f9602688c500009f71b41c (patch) | |
| tree | f44fa1e007d2253efcf038c6a12929c8f4e307ad | |
| parent | c64c7cc0b36256581c29311675af3f50b0f2df3e (diff) | |
| download | numpy-ec6b1aef8d81a06385f9602688c500009f71b41c.tar.gz | |
BUG: core: Fix memory leak in the C function boundarraymethod_repr.
`dtypes` must be DECREF'd before the function returns.
Closes gh-19931.
| -rw-r--r-- | numpy/core/src/multiarray/array_method.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/numpy/core/src/multiarray/array_method.c b/numpy/core/src/multiarray/array_method.c index 03d67c81b..c4db73c3b 100644 --- a/numpy/core/src/multiarray/array_method.c +++ b/numpy/core/src/multiarray/array_method.c @@ -466,7 +466,6 @@ NPY_NO_EXPORT PyTypeObject PyArrayMethod_Type = { }; - static PyObject * boundarraymethod_repr(PyBoundArrayMethodObject *self) { @@ -476,9 +475,11 @@ boundarraymethod_repr(PyBoundArrayMethodObject *self) if (dtypes == NULL) { return NULL; } - return PyUnicode_FromFormat( - "<np._BoundArrayMethod `%s` for dtypes %S>", - self->method->name, dtypes); + PyObject *repr = PyUnicode_FromFormat( + "<np._BoundArrayMethod `%s` for dtypes %S>", + self->method->name, dtypes); + Py_DECREF(dtypes); + return repr; } |
