Skip to content

Commit

Permalink
BUG: Fix refcounting errors found using pytest-leaks
Browse files Browse the repository at this point in the history
These are the clear errors I found based on pytest-leaks.  One day
it would be nice to fix up pytest-leaks to better support newer
versions of pytest and cleaning up fixtures...
  • Loading branch information
seberg authored and charris committed Dec 19, 2022
1 parent a5238a1 commit f2394fe
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
3 changes: 3 additions & 0 deletions numpy/core/src/multiarray/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ PyArray_FillWithScalar(PyArrayObject *arr, PyObject *obj)
PyArray_BYTES(arr), PyArray_STRIDES(arr),
descr, value);

if (PyDataType_REFCHK(descr)) {
PyArray_Item_XDECREF(value, descr);
}
PyMem_FREE(value_buffer_heap);
return retcode;
}
Expand Down
3 changes: 0 additions & 3 deletions numpy/core/src/umath/ufunc_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -6456,7 +6456,6 @@ py_resolve_dtypes_generic(PyUFuncObject *ufunc, npy_bool return_context,
/* Explicitly allow int, float, and complex for the "weak" types. */
else if (descr_obj == (PyObject *)&PyLong_Type) {
descr = PyArray_DescrFromType(NPY_LONG);
Py_INCREF(descr);
dummy_arrays[i] = (PyArrayObject *)PyArray_Empty(0, NULL, descr, 0);
if (dummy_arrays[i] == NULL) {
goto finish;
Expand All @@ -6468,7 +6467,6 @@ py_resolve_dtypes_generic(PyUFuncObject *ufunc, npy_bool return_context,
}
else if (descr_obj == (PyObject *)&PyFloat_Type) {
descr = PyArray_DescrFromType(NPY_DOUBLE);
Py_INCREF(descr);
dummy_arrays[i] = (PyArrayObject *)PyArray_Empty(0, NULL, descr, 0);
if (dummy_arrays[i] == NULL) {
goto finish;
Expand All @@ -6480,7 +6478,6 @@ py_resolve_dtypes_generic(PyUFuncObject *ufunc, npy_bool return_context,
}
else if (descr_obj == (PyObject *)&PyComplex_Type) {
descr = PyArray_DescrFromType(NPY_CDOUBLE);
Py_INCREF(descr);
dummy_arrays[i] = (PyArrayObject *)PyArray_Empty(0, NULL, descr, 0);
if (dummy_arrays[i] == NULL) {
goto finish;
Expand Down

0 comments on commit f2394fe

Please sign in to comment.