Merge pull request #16742 from mppf/fix-1367
Fix memory leak for global array type expressions
This PR fixes a leak apparent with code like this:
type arrOfArr = [1..2][100..200] int; writeln(arrOfArr:string);
This is visible in the existing test
The problem here is that evaluateAutoDestroy in normalize.cpp hoists some
temporaries out of forall-expr functions representing types into module
scope. Meanwhile, the change to callDestructors in PR #16430 caused it to
no longer deinitialize such globals (because it never found the
initialization because it is within another function). This commit
adjusts collectGlobals in callDestructors to delve into functions that
might return array types.
- [x] full local testing
- [x] types/typedefs/bradc/arrayTypedef.chpl no longer leaks
- [x] primers pass with verify+valgrind and do not leak
Reviewed by @e-kayrakli - thanks!
- can we manage memory for runtime types in a more principled manner,
perhaps following along with domains (where some functions return
unowned and some return owned)?