Fix some issues identified using clang's static analysis