More issues reported by Coverity

Mostly memory leak fixes