Skip to content

Commit 76807f0

Browse files
authored
Merge pull request numpy#26567 from seberg/fix-leaks-2
BUG: fix memory leaks found with valgrind (next)
2 parents acefc26 + 3e72f89 commit 76807f0

File tree

4 files changed

+11
-15
lines changed

4 files changed

+11
-15
lines changed

numpy/_core/src/multiarray/dtype_traversal.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -398,13 +398,6 @@ subarray_traverse_data_free(NpyAuxData *data)
398398
}
399399

400400

401-
/*
402-
* We seem to be neither using nor exposing this right now, so leave it NULL.
403-
* (The implementation below should be functional.)
404-
*/
405-
#define subarray_traverse_data_clone NULL
406-
407-
#ifndef subarray_traverse_data_clone
408401
/* traverse data copy function */
409402
static NpyAuxData *
410403
subarray_traverse_data_clone(NpyAuxData *data)
@@ -426,7 +419,6 @@ subarray_traverse_data_clone(NpyAuxData *data)
426419

427420
return (NpyAuxData *)newdata;
428421
}
429-
#endif
430422

431423

432424
static int
@@ -469,7 +461,7 @@ get_subarray_traverse_func(
469461

470462
auxdata->count = size;
471463
auxdata->base.free = &subarray_traverse_data_free;
472-
auxdata->base.clone = subarray_traverse_data_clone;
464+
auxdata->base.clone = &subarray_traverse_data_clone;
473465

474466
if (get_traverse_func(
475467
traverse_context, dtype, aligned,

numpy/_core/src/multiarray/dtype_traversal.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,22 @@ static inline int
6969
NPY_traverse_info_copy(
7070
NPY_traverse_info *traverse_info, NPY_traverse_info *original)
7171
{
72-
traverse_info->func = NULL;
72+
/* Note that original may be identical to traverse_info! */
7373
if (original->func == NULL) {
7474
/* Allow copying also of unused clear info */
75+
traverse_info->func = NULL;
7576
return 0;
7677
}
77-
traverse_info->auxdata = NULL;
7878
if (original->auxdata != NULL) {
7979
traverse_info->auxdata = NPY_AUXDATA_CLONE(original->auxdata);
8080
if (traverse_info->auxdata == NULL) {
81+
traverse_info->func = NULL;
8182
return -1;
8283
}
8384
}
85+
else {
86+
traverse_info->auxdata = NULL;
87+
}
8488
Py_INCREF(original->descr);
8589
traverse_info->descr = original->descr;
8690
traverse_info->func = original->func;

numpy/_core/src/multiarray/item_selection.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ PyArray_PutTo(PyArrayObject *self, PyObject* values0, PyObject *indices0,
397397
if ((ni > 0) && (PyArray_Size((PyObject *)self) == 0)) {
398398
PyErr_SetString(PyExc_IndexError,
399399
"cannot replace elements of an empty array");
400-
return NULL;
400+
goto fail;
401401
}
402402
Py_INCREF(PyArray_DESCR(self));
403403
values = (PyArrayObject *)PyArray_FromAny(values0, PyArray_DESCR(self), 0, 0,
@@ -419,9 +419,8 @@ PyArray_PutTo(PyArrayObject *self, PyObject* values0, PyObject *indices0,
419419
Py_INCREF(PyArray_DESCR(self));
420420
obj = (PyArrayObject *)PyArray_FromArray(self,
421421
PyArray_DESCR(self), flags);
422-
if (obj != self) {
423-
copied = 1;
424-
}
422+
copied = 1;
423+
assert(self != obj);
425424
self = obj;
426425
}
427426
max_item = PyArray_SIZE(self);

numpy/_core/src/umath/wrapping_array_method.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ wrapping_auxdata_free(wrapping_auxdata *wrapping_auxdata)
9696

9797
if (wrapping_auxdata_freenum < WRAPPING_AUXDATA_FREELIST_SIZE) {
9898
wrapping_auxdata_freelist[wrapping_auxdata_freenum] = wrapping_auxdata;
99+
wrapping_auxdata_freenum++;
99100
}
100101
else {
101102
PyMem_Free(wrapping_auxdata);

0 commit comments

Comments
 (0)