Add pointer check for NULL before dereference it.