Skip to content

Commit edb449d

Browse files
committed
BUG: fix memory leaks found by valgrind
1 parent cf39be1 commit edb449d

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

numpy/_core/src/multiarray/arraytypes.c.src

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4222,6 +4222,7 @@ NPY_NO_EXPORT PyArray_Descr *
42224222
PyArray_DescrFromType(int type)
42234223
{
42244224
PyArray_Descr *ret = NULL;
4225+
npy_bool is_stringdtype = (type == NPY_VSTRING || type == NPY_VSTRINGLTR);
42254226

42264227
if (type < 0) {
42274228
/*
@@ -4233,7 +4234,7 @@ PyArray_DescrFromType(int type)
42334234
*/
42344235
ret = NULL;
42354236
}
4236-
else if (type == NPY_VSTRING || type == NPY_VSTRINGLTR) {
4237+
else if (is_stringdtype) {
42374238
ret = (PyArray_Descr *)new_stringdtype_instance(NULL, 1);
42384239
}
42394240
// builtin legacy dtypes
@@ -4280,7 +4281,7 @@ PyArray_DescrFromType(int type)
42804281
PyErr_SetString(PyExc_ValueError,
42814282
"Invalid data-type for array");
42824283
}
4283-
else {
4284+
else if (!is_stringdtype) {
42844285
Py_INCREF(ret);
42854286
}
42864287

numpy/_core/src/multiarray/descriptor.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,6 +2025,7 @@ arraydescr_dealloc(PyArray_Descr *self)
20252025
{
20262026
Py_XDECREF(self->typeobj);
20272027
if (!PyDataType_ISLEGACY(self)) {
2028+
Py_TYPE(self)->tp_free((PyObject *)self);
20282029
return;
20292030
}
20302031
_PyArray_LegacyDescr *lself = (_PyArray_LegacyDescr *)self;

0 commit comments

Comments
 (0)