fix memory leak errors