forked from osmocom/wireshark
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.
This commit is contained in:
parent
bce7cbf529
commit
c2edb44a9a
|
@ -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()
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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_);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue