fix memory leak on uncaught error