Fix code analysis issues and a couple small memory leaks