fix memory leak in exceptional case