Fix coverity defects.

This fixes some defects found by coverity (static analysis tool).