8000 BUG: Fix refcount leak in ResultType · numpy/numpy@7d25b81 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7d25b81

Browse files
sebergcharris
authored andcommitted
BUG: Fix refcount leak in ResultType
This slightly reorganizes the error path handling (duplicating the freeing for the non-error path). It just seemed a bit clearer.
1 parent fa5754e commit 7d25b81

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

numpy/core/src/multiarray/convert_datatype.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,14 +1649,14 @@ PyArray_ResultType(
16491649
Py_DECREF(all_DTypes[i]);
16501650
}
16511651
if (common_dtype == NULL) {
1652-
goto finish;
1652+
goto error;
16531653
}
16541654

16551655
if (common_dtype->abstract) {
16561656
/* (ab)use default descriptor to define a default */
16571657
PyArray_Descr *tmp_descr = common_dtype->default_descr(common_dtype);
16581658
if (tmp_descr == NULL) {
1659-
goto finish;
1659+
goto error;
16601660
}
16611661
Py_INCREF(NPY_DTYPE(tmp_descr));
16621662
Py_SETREF(common_dtype, NPY_DTYPE(tmp_descr));
@@ -1689,20 +1689,18 @@ PyArray_ResultType(
16891689
PyObject *tmp = PyArray_GETITEM(
16901690
arrs[i-ndtypes], PyArray_BYTES(arrs[i-ndtypes]));
16911691
if (tmp == NULL) {
1692-
Py_SETREF(result, NULL);
1693-
goto finish;
1692+
goto error;
16941693
}
16951694
curr = common_dtype->discover_descr_from_pyobject(common_dtype, tmp);
16961695
Py_DECREF(tmp);
16971696
}
16981697
if (curr == NULL) {
1699-
Py_SETREF(result, NULL);
1700-
goto finish;
1698+
goto error;
17011699
}
17021700
Py_SETREF(result, common_dtype->common_instance(result, curr));
17031701
Py_DECREF(curr);
17041702
if (result == NULL) {
1705-
goto finish;
1703+
goto error;
17061704
}
17071705
}
17081706
}
@@ -1723,16 +1721,21 @@ PyArray_ResultType(
17231721
* Going from error to success should not really happen, but is
17241722
* probably OK if it does.
17251723
*/
1726-
Py_SETREF(result, NULL);
1727-
goto finish;
1724+
goto error;
17281725
}
17291726
/* Return the old "legacy" result (could warn here if different) */
17301727
Py_SETREF(result, legacy_result);
17311728
}
17321729

1733-
finish:
1730+
Py_DECREF(common_dtype);
17341731
PyMem_Free(info_on_heap);
17351732
return result;
1733+
1734+
error:
1735+
Py_XDECREF(result);
1736+
Py_XDECREF(common_dtype);
1737+
PyMem_Free(info_on_heap);
1738+
return NULL;
17361739
}
17371740

17381741

0 commit comments

Comments
 (0)
0