fix a few NULL dereference errors
more static analysis