fix errors found by clang analyzer, thanks scan-build