Fix some issues uncovered by coverity