Fix realloc bug when memmoving