[RDY] Coverity fix resource leaks 1b

Because github is messing up and doesn't seem to even refer to travis anymore on PR #790, I've cherry-picked the relevant commits and posted them here.