fix memory leak at shutdown