Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Add missing DECREF in new path #19280

Merged
merged 2 commits into from Jun 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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