fix null ptr exception as reported by Coverity

fix null ptr exception as reported by Coverity