DDF-953 fixed resource leaks and possible null pointers