fixed resource leaks found by coverity