fix memory cross border bug