Fix compiler warnings
Remove some memory leaks and other clang warnings