fixup the bug in memory allocate and init