Loops should be detected and the function terminated with an appropriate error message in such cases. See: https://www.webtrees.net/index.php/forum/help-for-release-2-2-x/40264-stack-overflow-solved#113470