Batch of fixes for issues found by static analysis.