Coverity fixes

**TL;DR:**
* one *severe* file descriptor resource leak
* one potential segfault in an error case
* some minor resource leaks in error cases
* uninitialized variable in error case

Conclusion: Except the first one, there was nothing utterly stupid :-)