Check for NULL before dereferencing.

Reported by STACK

http://css.csail.mit.edu/stack/

Change-Id: Id7959c8217f46313ecf35a271efaf5f703fde2dc