This was an incomplete attempt to get rid of the custom free function. Lets just keep it for now. Bug 637849, patch by Dan Winship. Also add a test case for this function.