Fix a few things found by scan-build and cppcheck