Fix use after free in MainWindow destructor.