Fix a bunch of issues reported by coverity.
Merge pull request #221 from adaptivecomputing/master

Fix a bunch of issues reported by coverity.