Added check to ensure malloced buffer is non-null prior to use.

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. This is the same as https://github.com/m1entus/MZAppearance/pull/3, just in a different location.