Skip to content

Commit

Permalink
BUG: Fix small valgrind-found issues (#18651)
Browse files Browse the repository at this point in the history
* BUG: Fix small valgrind-found issues

This should be backportable. There was at least one that I could
not reproduce when running the tests again. And the new random-shuffle
tests give false-positives (which is just slightly annoying, considering
that we are very close to almost only "longdouble" related
false-positives)

* BUG: Add missing decref in user-dtype fallback paths

The missing decref here only leaks references and can never leak
actual memory fortunately.

* MAINT,TST: Simplify the "refcount logic" in the dispatch tests again

Using SETREF can be nice, but was just overcomplicating thing here...
  • Loading branch information
seberg authored and charris committed Mar 21, 2021
1 parent b947264 commit b9edc25
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions numpy/core/src/multiarray/array_coercion.c
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,7 @@ find_descriptor_from_array(
NULL, DType, &flags, item_DType) < 0) {
Py_DECREF(iter);
Py_DECREF(elem);
Py_XDECREF(*out_descr);
Py_XDECREF(item_DType);
return -1;
}
Expand Down
1 change: 1 addition & 0 deletions numpy/core/src/multiarray/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,7 @@ void_getbuffer(PyObject *self, Py_buffer *view, int flags)
*/
_buffer_info_t *info = _buffer_get_info(&scalar->_buffer_info, self, flags);
if (info == NULL) {
Py_DECREF(self);
return -1;
}
view->format = info->format;
Expand Down
2 changes: 2 additions & 0 deletions numpy/core/src/multiarray/legacy_dtype_implementation.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,12 @@ PyArray_LegacyCanCastSafely(int fromtype, int totype)

while (*curtype != NPY_NOTYPE) {
if (*curtype++ == totype) {
Py_DECREF(from);
return 1;
}
}
}
Py_DECREF(from);
return 0;
}

Expand Down
1 change: 1 addition & 0 deletions numpy/core/src/umath/_umath_tests.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ UMath_Tests_test_dispatch(PyObject *NPY_UNUSED(dummy), PyObject *NPY_UNUSED(dumm
if (item == NULL || PyDict_SetItemString(dict, "@str@", item) < 0) {
goto err;
}
Py_DECREF(item);
/**end repeat**/
item = PyList_New(0);
if (item == NULL || PyDict_SetItemString(dict, "all", item) < 0) {
Expand Down
2 changes: 1 addition & 1 deletion numpy/core/tests/test_multiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -7479,7 +7479,7 @@ def test_out_of_order_fields(self):
memoryview(arr)

def test_max_dims(self):
a = np.empty((1,) * 32)
a = np.ones((1,) * 32)
self._check_roundtrip(a)

@pytest.mark.slow
Expand Down

0 comments on commit b9edc25

Please sign in to comment.