Fix some issues spotted by coverity scan

Compile tested only