A bunch of C++ cleanup; lots of leaks, bad iterator usage, etc.

Most of this I found running cppcheck, which is a tool for static code analysis.  There's some lingering memory leak issues and some architectural issues with the code that the project might consider reworking.