DDF-953 - fixed resource leaks and null references found by coverity