Fixed clang warnings and memory leaks.