Fix some leaks reported by Coverity scan

Compile tested only, please review.