Added check for malloc return.
Patch by Victor Campos.
Differential Revision: https://reviews.llvm.org/D26318