Coverity fixes (mostly resource leaks)

> To clear the haystack, start by picking up a few pieces of hay.
>   -- ancient chinese proverb

Not really, but I was looking at the coverity log and decided to throw in a few tiny fixes.