MFC r279276: Add checks for malloc() failures.
Submitted by: Dmitry Luhtionov <dmitryluhtionov@gmail.com>