[Chapel Merge] Close an EndCount leak in throwing foralls

Branch: refs/heads/master
Revision: 3869262
Author: e-kayrakli
Log Message:

Merge pull request #17328 from e-kayrakli/close-throwing-forall-leak

Close an EndCount leak in throwing foralls

This PR closes a leak with foralls whose body throw error(s).

Resolves Memory leaks from #12225 (and parallel error-handling in general) · Issue #12511 · chapel-lang/chapel · GitHub

@mppf summarized the problem under that issue:

We had defer blocks for the EndCount to make sure it is deleted. But these are
processed (and changed to delete calls at the end of a block) in
callDestructors. Then, lowerIterators lowers the ForallStmt into a more
complex structure and no longer calls the delete if the body of the forall
threw an error. I believe that this is only a problem now that ForallStmts get
lowered later.

With this PR, lowerIterators now finds any endCountFree calls that show up
between the error's goto and the associated label, and creates a copy of that
endCountFree right before the goto.

[Reviewed by @vasslitvinov]

Test Status