Which satisfies the infinite loop issue.
Have not looked carefully at the dynamic allocation, but I am guessing (hand waving here....) that it could be accomplished.