Closed memory leaks and compiler warnings.

A bunch of memory leaks and compiler warnings have been resolved. We
are heading towards a warning free build.