Add additional checks for malloc failures.
Fix warnings introduced by e312b6a06d2ec1f79b8d9c671a48cf0d8a0b2dfd