add out of memory checks to mallocs