Fix some bugs reported by clang-analyzer