Fixed errors reported by coverity (mostly missing null checks after some allocs)