arr is now freed after use rather than before