aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2020-03-22 11:21:58 -0700
committerAnders Broman <a.broman58@gmail.com>2020-03-25 08:32:16 +0000
commit12d5041eb7cbd5b28567ac58b140864561fadccd (patch)
tree77c31985a535aa089568272e8a713adce39b257c
parent21ed54aba132ff598a68b8b7474d60268f369456 (diff)
Qt: Fix Lua GUI issues and get rid of casts.
Define a FunnelStatistics dtor and use it to clear our funnel operations. This keeps us from crashing if we quit while a ProgDlg or TextWindow is visible. In FunnelStatistics::progressDialogNew, pass in our parent MainWindow instead of depending on capture_file_ having a valid window pointer. This lets us use a ProgDlg without having to load a capture file. Define and use the _funnel_ops_id_t struct so that we don't have to cast void pointers in a bunch of places. Change-Id: I38dd3f254b705ddf82f7421a14d27b8c3ef7bc98 Reviewed-on: https://code.wireshark.org/review/36538 Reviewed-by: Gerald Combs <gerald@wireshark.org> Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r--ui/qt/funnel_statistics.cpp65
-rw-r--r--ui/qt/funnel_statistics.h3
2 files changed, 40 insertions, 28 deletions
diff --git a/ui/qt/funnel_statistics.cpp b/ui/qt/funnel_statistics.cpp
index eefcf7980d..b7a75bb8e1 100644
--- a/ui/qt/funnel_statistics.cpp
+++ b/ui/qt/funnel_statistics.cpp
@@ -57,7 +57,7 @@ static void progress_window_destroy(struct progdlg *progress_dialog);
class FunnelAction : public QAction
{
public:
- FunnelAction(const QString title, funnel_menu_callback callback, gpointer callback_data, gboolean retap, QObject *parent = 0) :
+ FunnelAction(const QString title, funnel_menu_callback callback, gpointer callback_data, gboolean retap, QObject *parent = nullptr) :
QAction(parent),
title_(title),
callback_(callback),
@@ -98,6 +98,10 @@ static QHash<int, QList<FunnelAction *> > funnel_actions_;
const QString FunnelStatistics::action_name_ = "FunnelStatisticsAction";
static gboolean menus_registered = FALSE;
+struct _funnel_ops_id_t {
+ FunnelStatistics *funnel_statistics;
+};
+
FunnelStatistics::FunnelStatistics(QObject *parent, CaptureFile &cf) :
QObject(parent),
capture_file_(cf),
@@ -105,8 +109,10 @@ FunnelStatistics::FunnelStatistics(QObject *parent, CaptureFile &cf) :
{
funnel_ops_ = new(struct _funnel_ops_t);
memset(funnel_ops_, 0, sizeof(struct _funnel_ops_t));
+ funnel_ops_id_ = new(struct _funnel_ops_id_t);
- funnel_ops_->ops_id = (funnel_ops_id_t*) this;
+ funnel_ops_id_->funnel_statistics = this;
+ funnel_ops_->ops_id = funnel_ops_id_;
funnel_ops_->new_text_window = text_window_new;
funnel_ops_->set_text = text_window_set_text;
funnel_ops_->append_text = text_window_append;
@@ -138,6 +144,17 @@ FunnelStatistics::FunnelStatistics(QObject *parent, CaptureFile &cf) :
funnel_set_funnel_ops(funnel_ops_);
}
+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_);
+}
+
void FunnelStatistics::retapPackets()
{
capture_file_.retapPackets();
@@ -145,7 +162,7 @@ void FunnelStatistics::retapPackets()
struct progdlg *FunnelStatistics::progressDialogNew(const gchar *task_title, const gchar *item_title, gboolean terminate_is_stop, gboolean *stop_flag)
{
- return create_progress_dlg(capture_file_.window(), task_title, item_title, terminate_is_stop, stop_flag);
+ return create_progress_dlg(parent(), task_title, item_title, terminate_is_stop, stop_flag);
}
const char *FunnelStatistics::displayFilter()
@@ -203,10 +220,9 @@ void funnel_statistics_logger(const gchar *,
}
void funnel_statistics_retap_packets(funnel_ops_id_t *ops_id) {
- FunnelStatistics *funnel_statistics = dynamic_cast<FunnelStatistics *>((FunnelStatistics *)ops_id);
- if (!funnel_statistics) return;
+ if (!ops_id || !ops_id->funnel_statistics) return;
- funnel_statistics->retapPackets();
+ ops_id->funnel_statistics->retapPackets();
}
void funnel_statistics_copy_to_clipboard(GString *text) {
@@ -214,21 +230,19 @@ void funnel_statistics_copy_to_clipboard(GString *text) {
}
const gchar *funnel_statistics_get_filter(funnel_ops_id_t *ops_id) {
- FunnelStatistics *funnel_statistics = dynamic_cast<FunnelStatistics *>((FunnelStatistics *)ops_id);
- if (!funnel_statistics) return NULL;
+ if (!ops_id || !ops_id->funnel_statistics) return nullptr;
- return funnel_statistics->displayFilter();
+ return ops_id->funnel_statistics->displayFilter();
}
void funnel_statistics_set_filter(funnel_ops_id_t *ops_id, const char* filter_string) {
- FunnelStatistics *funnel_statistics = dynamic_cast<FunnelStatistics *>((FunnelStatistics *)ops_id);
- if (!funnel_statistics) return;
+ if (!ops_id || !ops_id->funnel_statistics) return;
- funnel_statistics->emitSetDisplayFilter(filter_string);
+ ops_id->funnel_statistics->emitSetDisplayFilter(filter_string);
}
void funnel_statistics_set_color_filter_slot(guint8 filter_num, const gchar* filter_string) {
- gchar *err_msg = NULL;
+ gchar *err_msg = nullptr;
if (!color_filters_set_tmp(filter_num, filter_string, FALSE, &err_msg)) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg);
g_free(err_msg);
@@ -239,34 +253,30 @@ gboolean funnel_statistics_open_file(funnel_ops_id_t *ops_id, const char* fname,
// XXX We need to return a proper error value. We should probably move
// MainWindow::openCaptureFile to CaptureFile and add error handling
// there.
- FunnelStatistics *funnel_statistics = dynamic_cast<FunnelStatistics *>((FunnelStatistics *)ops_id);
- if (!funnel_statistics) return FALSE;
+ if (!ops_id || !ops_id->funnel_statistics) return FALSE;
QString cf_name(fname);
QString cf_filter(filter);
- funnel_statistics->emitOpenCaptureFile(cf_name, cf_filter);
+ ops_id->funnel_statistics->emitOpenCaptureFile(cf_name, cf_filter);
return TRUE;
}
void funnel_statistics_reload_packets(funnel_ops_id_t *ops_id) {
- FunnelStatistics *funnel_statistics = dynamic_cast<FunnelStatistics *>((FunnelStatistics *)ops_id);
- if (!funnel_statistics) return;
+ if (!ops_id || !ops_id->funnel_statistics) return;
- funnel_statistics->reloadPackets();
+ ops_id->funnel_statistics->reloadPackets();
}
void funnel_statistics_reload_lua_plugins(funnel_ops_id_t *ops_id) {
- FunnelStatistics *funnel_statistics = dynamic_cast<FunnelStatistics *>((FunnelStatistics *)ops_id);
- if (!funnel_statistics) return;
+ if (!ops_id || !ops_id->funnel_statistics) return;
- funnel_statistics->reloadLuaPlugins();
+ ops_id->funnel_statistics->reloadLuaPlugins();
}
void funnel_statistics_apply_filter(funnel_ops_id_t *ops_id) {
- FunnelStatistics *funnel_statistics = dynamic_cast<FunnelStatistics *>((FunnelStatistics *)ops_id);
- if (!funnel_statistics) return;
+ if (!ops_id || !ops_id->funnel_statistics) return;
- funnel_statistics->emitApplyDisplayFilter();
+ ops_id->funnel_statistics->emitApplyDisplayFilter();
}
gboolean browser_open_url(const gchar *url) {
@@ -278,10 +288,9 @@ void browser_open_data_file(const gchar *filename) {
}
struct progdlg *progress_window_new(funnel_ops_id_t *ops_id, const gchar* task_title, const gchar* item_title, gboolean terminate_is_stop, gboolean *stop_flag) {
- FunnelStatistics *funnel_statistics = dynamic_cast<FunnelStatistics *>((FunnelStatistics *)ops_id);
- if (!funnel_statistics) return NULL;
+ if (!ops_id || !ops_id->funnel_statistics) return nullptr;
- return funnel_statistics->progressDialogNew(task_title, item_title, terminate_is_stop, stop_flag);
+ return ops_id->funnel_statistics->progressDialogNew(task_title, item_title, terminate_is_stop, stop_flag);
}
void progress_window_update(struct progdlg *progress_dialog, float percentage, const gchar* status) {
diff --git a/ui/qt/funnel_statistics.h b/ui/qt/funnel_statistics.h
index 7a224d92a2..8c1a363200 100644
--- a/ui/qt/funnel_statistics.h
+++ b/ui/qt/funnel_statistics.h
@@ -25,6 +25,7 @@ class FunnelStatistics : public QObject
Q_OBJECT
public:
explicit FunnelStatistics(QObject *parent, CaptureFile &cf);
+ ~FunnelStatistics();
void retapPackets();
struct progdlg *progressDialogNew(const gchar *task_title, const gchar *item_title, gboolean terminate_is_stop, gboolean *stop_flag);
const char *displayFilter();
@@ -46,6 +47,8 @@ public slots:
private:
static const QString action_name_;
struct _funnel_ops_t *funnel_ops_;
+ struct _funnel_ops_id_t *funnel_ops_id_;
+
CaptureFile &capture_file_;
QByteArray display_filter_;
QString prepared_filter_;