Skip to content

Commit

Permalink
Merge pull request #19280 from charris/backport-19277
Browse files Browse the repository at this point in the history
BUG: Add missing DECREF in new path
  • Loading branch information
charris committed Jun 19, 2021
2 parents 61127bb + 7d25b81 commit 032fca5
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions numpy/core/src/multiarray/convert_datatype.c
Expand Up @@ -476,6 +476,7 @@ PyArray_CheckCastSafety(NPY_CASTING casting,

if (PyArray_MinCastSafety(castingimpl->casting, casting) == casting) {
/* No need to check using `castingimpl.resolve_descriptors()` */
Py_DECREF(meth);
return 1;
}

Expand Down Expand Up @@ -1648,14 +1649,14 @@ PyArray_ResultType(
Py_DECREF(all_DTypes[i]);
}
if (common_dtype == NULL) {
goto finish;
goto error;
}

if (common_dtype->abstract) {
/* (ab)use default descriptor to define a default */
PyArray_Descr *tmp_descr = common_dtype->default_descr(common_dtype);
if (tmp_descr == NULL) {
goto finish;
goto error;
}
Py_INCREF(NPY_DTYPE(tmp_descr));
Py_SETREF(common_dtype, NPY_DTYPE(tmp_descr));
Expand Down Expand Up @@ -1688,20 +1689,18 @@ PyArray_ResultType(
PyObject *tmp = PyArray_GETITEM(
arrs[i-ndtypes], PyArray_BYTES(arrs[i-ndtypes]));
if (tmp == NULL) {
Py_SETREF(result, NULL);
goto finish;
goto error;
}
curr = common_dtype->discover_descr_from_pyobject(common_dtype, tmp);
Py_DECREF(tmp);
}
if (curr == NULL) {
Py_SETREF(result, NULL);
goto finish;
goto error;
}
Py_SETREF(result, common_dtype->common_instance(result, curr));
Py_DECREF(curr);
if (result == NULL) {
goto finish;
goto error;
}
}
}
Expand All @@ -1722,16 +1721,21 @@ PyArray_ResultType(
* Going from error to success should not really happen, but is
* probably OK if it does.
*/
Py_SETREF(result, NULL);
goto finish;
goto error;
}
/* Return the old "legacy" result (could warn here if different) */
Py_SETREF(result, legacy_result);
}

finish:
Py_DECREF(common_dtype);
PyMem_Free(info_on_heap);
return result;

error:
Py_XDECREF(result);
Py_XDECREF(common_dtype);
PyMem_Free(info_on_heap);
return NULL;
}


Expand Down

0 comments on commit 032fca5

Please sign in to comment.