handle out-of-memory gracefully; get rid of the XMALLOC/XFREE insanity