Fix memory leaks reported by coverity