Fixed some bugs/lints found by scan-build (part of Clang/LLVM).