fix memory leak on thrown exception