Skip to content

Commit

Permalink
Merge pull request #23941 from seberg/einsum-err-cleanup
Browse files Browse the repository at this point in the history
BUG: Fix NpyIter cleanup in einsum error path
  • Loading branch information
mattip committed Jun 14, 2023
2 parents 59e8c62 + e87676e commit 26edc98
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions numpy/core/src/multiarray/einsum.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ PyArray_EinsteinSum(char *subscripts, npy_intp nop,
int *op_axes[NPY_MAXARGS];
npy_uint32 iter_flags, op_flags[NPY_MAXARGS];

NpyIter *iter;
NpyIter *iter = NULL;
sum_of_products_fn sop;
npy_intp fixed_strides[NPY_MAXARGS];

Expand Down Expand Up @@ -1133,7 +1133,6 @@ PyArray_EinsteinSum(char *subscripts, npy_intp nop,

iternext = NpyIter_GetIterNext(iter, NULL);
if (iternext == NULL) {
NpyIter_Deallocate(iter);
goto fail;
}
dataptr = NpyIter_GetDataPtrArray(iter);
Expand Down Expand Up @@ -1168,6 +1167,7 @@ finish:
return ret;

fail:
NpyIter_Deallocate(iter);
for (iop = 0; iop < nop; ++iop) {
Py_XDECREF(op[iop]);
}
Expand Down

0 comments on commit 26edc98

Please sign in to comment.