Fix some more coverity issues. Various memory leaks and the like.