Fixed a few compiler warnings.

I fixed a number of potential memory leaks that were shown as clang warnings.