Fix possible null ptr derefs reported by Coverity.