Coverity static analysis

We've has joined Coverity Scan [open source project scanning](https://scan.coverity.com/projects). This is a first batch of things it found. These are failures to close files and streams.