Text leak fix

I reverted a change that didn't make it into the original pull request, leaving only the leak fix.