macosx: fixed a few bugs found by clang's code analysis