Skip to content

Commit 0ed58f8

Browse files
BUG: ufunc: Fix potential memory leak. (numpy#19925)
* BUG: ufunc: Fix potential memory leak. Change a return statement to 'goto fail;' to ensure that memory previously allocated with PyArray_malloc() is freed. (The memory pointers are 'funcdata' and 'newtypes'.) The return *value* in this case is also changed, from 0 to -1, to indicate that an error occurred. The exceptional return occurs because an unexpected error occurred in the call to PyDict_GetItemWithError. Closes numpygh-19548.
1 parent 24c4436 commit 0ed58f8

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

numpy/core/src/umath/ufunc_object.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5578,8 +5578,7 @@ PyUFunc_RegisterLoopForType(PyUFuncObject *ufunc,
55785578
/* Get entry for this user-defined type*/
55795579
cobj = PyDict_GetItemWithError(ufunc->userloops, key);
55805580
if (cobj == NULL && PyErr_Occurred()) {
5581-
Py_DECREF(key);
5582-
return 0;
5581+
goto fail;
55835582
}
55845583
/* If it's not there, then make one and return. */
55855584
else if (cobj == NULL) {

0 commit comments

Comments
 (0)