add a number of null check to return methods.

This allows calling these methods on error cleanup paths without having
to surround them with if checks all the time.