diff options
author | Tomasz Moń <desowin@gmail.com> | 2021-04-03 18:29:11 +0200 |
---|---|---|
committer | Wireshark GitLab Utility <gerald+gitlab-utility@wireshark.org> | 2021-08-29 08:50:57 +0000 |
commit | c2edb44a9ac2bcd6bff267bd4d7301caff248eca (patch) | |
tree | 0e02dd70d1b2d748b0cf927724fb0bf657ba7cb7 /ui/qt | |
parent | bce7cbf52967a78319251f4d66fd0a21424c4504 (diff) |
Qt: fix memory leaks found by Visual Leak Detector
Set PacketDiagram as parent of QGraphicsScene so the scene is destroyed
together with PacketDiagram.
Dynamically allocate WiresharkApplication and explicitly call its
destructor when no longer needed. This results in deletion of
FunnelAction objects created in register_menu_cb() and QAction objects
created in TapParameterDialog::registerDialog(). For some reason, when
breakpoint was set inside WiresharkApplication destructor it would not
get triggered on exit, and so the child objects would get reported as
memory leaks.
Delete main window and application only after epan_cleanup(). This makes
lua plugins actually call ops during cleanup (e.g. destroy_text_window)
and makes it possible to free the memory allocated in FunnelStatistics
constructor.
Diffstat (limited to 'ui/qt')
-rw-r--r-- | ui/qt/funnel_statistics.cpp | 9 | ||||
-rw-r--r-- | ui/qt/main.cpp | 14 | ||||
-rw-r--r-- | ui/qt/packet_diagram.cpp | 2 | ||||
-rw-r--r-- | ui/qt/wireshark_application.cpp | 2 |
4 files changed, 11 insertions, 16 deletions
diff --git a/ui/qt/funnel_statistics.cpp b/ui/qt/funnel_statistics.cpp index 4bbaba8828..a56492c339 100644 --- a/ui/qt/funnel_statistics.cpp +++ b/ui/qt/funnel_statistics.cpp @@ -155,13 +155,8 @@ FunnelStatistics::FunnelStatistics(QObject *parent, CaptureFile &cf) : FunnelStatistics::~FunnelStatistics() { - // At this point we're probably closing the program and will shortly - // call epan_cleanup, which calls ProgDlg__gc and TextWindow__gc. - // They in turn depend on funnel_ops_ being valid. - memset(funnel_ops_id_, 0, sizeof(struct _funnel_ops_id_t)); - memset(funnel_ops_, 0, sizeof(struct _funnel_ops_t)); - // delete(funnel_ops_id_); - // delete(funnel_ops_); + delete(funnel_ops_id_); + delete(funnel_ops_); } void FunnelStatistics::retapPackets() diff --git a/ui/qt/main.cpp b/ui/qt/main.cpp index efb55caad6..b7107ad557 100644 --- a/ui/qt/main.cpp +++ b/ui/qt/main.cpp @@ -693,7 +693,7 @@ int main(int argc, char *qt_argv[]) #endif /* Create The Wireshark app */ - WiresharkApplication ws_app(argc, qt_argv); + wsApp = new WiresharkApplication(argc, qt_argv); /* initialize the funnel mini-api */ // xxx qtshark @@ -737,9 +737,9 @@ int main(int argc, char *qt_argv[]) main_w->show(); // We may not need a queued connection here but it would seem to make sense // to force the issue. - main_w->connect(&ws_app, SIGNAL(openCaptureFile(QString,QString,unsigned int)), + main_w->connect(wsApp, SIGNAL(openCaptureFile(QString,QString,unsigned int)), main_w, SLOT(openCaptureFile(QString,QString,unsigned int))); - main_w->connect(&ws_app, SIGNAL(openCaptureOptions()), + main_w->connect(wsApp, SIGNAL(openCaptureOptions()), main_w, SLOT(on_actionCaptureOptions_triggered())); /* Init the "Open file" dialog directory */ @@ -832,7 +832,7 @@ int main(int argc, char *qt_argv[]) ws_log(LOG_DOMAIN_MAIN, LOG_LEVEL_INFO, "Calling module preferences, elapsed time %" G_GUINT64_FORMAT " us \n", g_get_monotonic_time() - start_time); #endif - global_commandline_info.prefs_p = ws_app.readConfigurationFiles(false); + global_commandline_info.prefs_p = wsApp->readConfigurationFiles(false); /* Now get our args */ commandline_other_options(argc, argv, TRUE); @@ -1061,12 +1061,14 @@ int main(int argc, char *qt_argv[]) profile_store_persconffiles(FALSE); ret_val = wsApp->exec(); - wsApp = NULL; - delete main_w; recent_cleanup(); epan_cleanup(); + delete main_w; + delete wsApp; + wsApp = NULL; + extcap_cleanup(); Dot11DecryptDestroyContext(&dot11decrypt_ctx); diff --git a/ui/qt/packet_diagram.cpp b/ui/qt/packet_diagram.cpp index 3350c2c3fb..adc9948e2b 100644 --- a/ui/qt/packet_diagram.cpp +++ b/ui/qt/packet_diagram.cpp @@ -523,7 +523,7 @@ void PacketDiagram::resetScene(bool reset_root) if (scene()) { delete scene(); } - QGraphicsScene *new_scene = new QGraphicsScene(); + QGraphicsScene *new_scene = new QGraphicsScene(this); setScene(new_scene); connect(new_scene, &QGraphicsScene::selectionChanged, this, &PacketDiagram::sceneSelectionChanged); setRootNode(reset_root ? nullptr : root_node_); diff --git a/ui/qt/wireshark_application.cpp b/ui/qt/wireshark_application.cpp index 676b598a23..86a1e2934c 100644 --- a/ui/qt/wireshark_application.cpp +++ b/ui/qt/wireshark_application.cpp @@ -629,7 +629,6 @@ WiresharkApplication::WiresharkApplication(int &argc, char **argv) : if_notifier_(NULL), active_captures_(0) { - wsApp = this; setApplicationName("Wireshark"); MimeDatabaseInitThread *mime_db_init_thread = new(MimeDatabaseInitThread); @@ -779,7 +778,6 @@ WiresharkApplication::WiresharkApplication(int &argc, char **argv) : WiresharkApplication::~WiresharkApplication() { - wsApp = NULL; clearDynamicMenuGroupItems(); free_filter_lists(); } |