Add additional checks for NULL pointers to fix several crashes reported.

ASTERISK-24304 #close
Reported by: dhanapathy sathya
........

Merged revisions 426666 from http://svn.asterisk.org/svn/asterisk/branches/11


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/12@426667 f38db490-d61c-443f-a65b-d21fe96a405b