Fix coverity

Fixes for a few issues found by coverity in the code we merged recently.