Skip to content

Commit ec6b1ae

Browse files
BUG: core: Fix memory leak in the C function boundarraymethod_repr.
`dtypes` must be DECREF'd before the function returns. Closes numpygh-19931.
1 parent c64c7cc commit ec6b1ae

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

numpy/core/src/multiarray/array_method.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,6 @@ NPY_NO_EXPORT PyTypeObject PyArrayMethod_Type = {
466466
};
467467

468468

469-
470469
static PyObject *
471470
boundarraymethod_repr(PyBoundArrayMethodObject *self)
472471
{
@@ -476,9 +475,11 @@ boundarraymethod_repr(PyBoundArrayMethodObject *self)
476475
if (dtypes == NULL) {
477476
return NULL;
478477
}
479-
return PyUnicode_FromFormat(
480-
"<np._BoundArrayMethod `%s` for dtypes %S>",
481-
self->method->name, dtypes);
478+
PyObject *repr = PyUnicode_FromFormat(
479+
"<np._BoundArrayMethod `%s` for dtypes %S>",
480+
self->method->name, dtypes);
481+
Py_DECREF(dtypes);
482+
return repr;
482483
}
483484

484485

0 commit comments

Comments
 (0)