reindenting the uncrustified code by Xcode
fixed memory leaks and clang warnings
Pulled in upsteam changes