Exit with error message on memory alloc failure