Fixed bugs in Mem_Alloc