window: fix memory leak