Fix dead store which Clang Static Analyser pointed out,
and some style changes. No functional changes.
Fix garbag return value which Clang Static Analyser pointed out.
Plug memory leaks which Clang Static Analyser pointed out.
Fix dereference of null pointer which Clang Static Analyser pointed out.
Style fix. space -> tab.