fix memory allocation error