fix memory allocation issue