Fix memory leaks from a commit for bug #508744

I missed that part when copying the code from a test program I cooked.