Fixed a missing initialization found by clang analyzer.

Various code style fixes
Fix a warning about possible NULL dereferencing.
Use unique_ptr<> instead of raw pointer.

Minor code style fixes / reindent
Use C++11 nullptr