From 3da24bb449c312e51086734cf935c0c661e1f95f Mon Sep 17 00:00:00 2001 From: Sebastian Berg Date: Fri, 9 Sep 2022 09:59:29 +0200 Subject: [PATCH] BUG: Fix incorrect refcounting in new `asarray` path The new path to preserve dtypes provided by creating a view got the reference counting wrong, because it also hit the incref path that was needed for returning the identity. This fixes up gh-21995 Closes gh-22233 --- numpy/core/src/multiarray/multiarraymodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c index f01752431b4d..f8e7d37c3651 100644 --- a/numpy/core/src/multiarray/multiarraymodule.c +++ b/numpy/core/src/multiarray/multiarraymodule.c @@ -1631,8 +1631,8 @@ _array_fromobject_generic( oldtype = PyArray_DESCR(oparr); if (PyArray_EquivTypes(oldtype, type)) { if (copy != NPY_COPY_ALWAYS && STRIDING_OK(oparr, order)) { - Py_INCREF(op); if (oldtype == type) { + Py_INCREF(op); ret = oparr; } else {