Add a checked alloc.

Instead of calling malloc directly, call into a routine that checks for
out-of-memory errors.