From a8a3903e55af23bdce550a95ffe14a398fd1204c Mon Sep 17 00:00:00 2001 From: Mikael Kanstrup Date: Mon, 25 Sep 2017 23:18:31 +0200 Subject: Qt: Free MainWindow at shutdown MainWindow is allocated on heap on startup but not freed on shutdown. Free the object at shutdown mainly to silent Valgrind. When at it also fix two problems with the MainWindow destructor: - Deleting main_ui_ triggers a currentChanged signal which in turn calls mainStackChanged that references the freed main_ui_ object. Prevent use after free error by disconnecting from the signal before freeing. - Explicitly free file_set_dialog_ as no rparent perform the cleanup. Bug: 14071 Change-Id: I9c1fbef04cf68bfffffea57ef298f4896d6583f9 Reviewed-on: https://code.wireshark.org/review/23739 Reviewed-by: Gerald Combs Petri-Dish: Gerald Combs Tested-by: Petri Dish Buildbot Reviewed-by: Michael Mann --- ui/qt/main_window.cpp | 10 ++++++++++ wireshark-qt.cpp | 1 + 2 files changed, 11 insertions(+) diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp index 1d1e9eb24b..e7fcc99032 100644 --- a/ui/qt/main_window.cpp +++ b/ui/qt/main_window.cpp @@ -736,6 +736,16 @@ MainWindow::MainWindow(QWidget *parent) : MainWindow::~MainWindow() { + disconnect(main_ui_->mainStack, 0, 0, 0); + +#ifndef Q_OS_MAC + // file_set_dialog_ is a subclass of GeometryStateDialog. + // For reasons described in geometry_state_dialog.h no parent is set when + // instantiating the dialog and as a result the object is not automatically + // freed by its parent. Free it here explicitly to avoid leak and numerous + // Valgrind complaints. + delete file_set_dialog_; +#endif delete main_ui_; } diff --git a/wireshark-qt.cpp b/wireshark-qt.cpp index 61fac58a59..538994daef 100644 --- a/wireshark-qt.cpp +++ b/wireshark-qt.cpp @@ -939,6 +939,7 @@ int main(int argc, char *qt_argv[]) ret_val = wsApp->exec(); + delete main_w; recent_cleanup(); epan_cleanup(); -- cgit v1.2.3