Added check for unlikely case where malloc fails and returns NULL

Added check for the rare case where a malloc could fail and return NULL as a
result. This is primarily to make a static scan tool happy.
Merge pull request #3 from nmccann/security_fix

Added check for unlikely case where malloc fails and returns NULL