fix memory bug