Fixed resource leaks detected by coverity