Fixed Resource Leaks, null dereferences, few other issues reported by coverity