fixed errors in mem_alloc