Fix a bunch of coverity issues.