8000 Merge pull request #19280 from charris/backport-19277 · numpy/numpy@032fca5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 032fca5

Browse files
authored
Merge pull request #19280 from charris/backport-19277
BUG: Add missing DECREF in new path
2 parents 61127bb + 7d25b81 commit 032fca5

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

numpy/core/src/multiarray/convert_datatype.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ PyArray_CheckCastSafety(NPY_CASTING casting,
476476

477477
if (PyArray_MinCastSafety(castingimpl->casting, casting) == casting) {
478478
/* No need to check using `castingimpl.resolve_descriptors()` */
479+
Py_DECREF(meth);
479480
return 1;
480481
}
481482

@@ -1648,14 +1649,14 @@ PyArray_ResultType(
16481649
Py_DECREF(all_DTypes[i]);
16491650
}
16501651
if (common_dtype == NULL) {
1651-
goto finish;
1652+
goto error;
16521653
}
16531654

16541655
if (common_dtype->abstract) {
16551656
/* (ab)use default descriptor to define a default */
16561657
PyArray_Descr *tmp_descr = common_dtype->default_descr(common_dtype);
16571658
if (tmp_descr == NULL) {
1658-
goto finish;
1659+
goto error;
16591660
}
16601661
Py_INCREF(NPY_DTYPE(tmp_descr));
16611662
Py_SETREF(common_dtype, NPY_DTYPE(tmp_descr));
@@ -1688,20 +1689,18 @@ PyArray_ResultType(
16881689
PyObject *tmp = PyArray_GETITEM(
16891690
arrs[i-ndtypes], PyArray_BYTES(arrs[i-ndtypes]));
16901691
if (tmp == NULL) {
1691-
Py_SETREF(result, NULL);
1692-
goto finish;
1692+
goto error;
16931693
}
16941694
curr = common_dtype->discover_descr_from_pyobject(common_dtype, tmp);
16951695
Py_DECREF(tmp);
16961696
}
16971697
if (curr == NULL) {
1698-
Py_SETREF(result, NULL);
1699-
goto finish;
1698+
goto error;
17001699
}
17011700
Py_SETREF(result, common_dtype->common_instance(result, curr));
17021701
Py_DECREF(curr);
17031702
if (result == NULL) {
1704-
goto finish;
1703+
goto error;
17051704
}
17061705
}
17071706
}
@@ -1722,16 +1721,21 @@ PyArray_ResultType(
17221721
* Going from error to success should not really happen, but is
17231722
* probably OK if it does.
17241723
*/
1725-
Py_SETREF(result, NULL);
1726-
goto finish;
1724+
goto error;
17271725
}
17281726
/* Return the old "legacy" result (could warn here if different) */
17291727
Py_SETREF(result, legacy_result);
17301728
}
17311729

1732-
finish:
1730+
Py_DECREF(common_dtype);
17331731
PyMem_Free(info_on_heap);
17341732
return result;
1733+
1734+
error:
1735+
Py_XDECREF(result);
1736+
Py_XDECREF(common_dtype);
1737+
PyMem_Free(info_on_heap);
1738+
return NULL;
17351739
}
17361740

17371741

0 commit comments

Comments
 (0)
0