Skip to content

Commit

Permalink
Merge pull request #22832 from charris/backport-22798
Browse files Browse the repository at this point in the history
BUG: Fix refcounting errors found using pytest-leaks
  • Loading branch information
charris committed Dec 19, 2022
2 parents ac22ecd + f2394fe commit c5be82e
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
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
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 c5be82e

Please sign in to comment.