SCA and Coverity fixes

Several fixes for issues found via SCA (Coverity and cppcheck)