always check that malloc() did not return NULL

Also, make memory allocation failures fatal in main()