forked from osmocom/wireshark
Qt: Fix leak in CaptureFileDialog
Instead of instantiating CaptureFileDialog with a reference to the filter (which means allocating a new empty QString when using it for Save As and Export Packets, which don't use a filter), pass the filter reference into the open and merge functions. This plugs a memory leak that happened each time the Save As or Export Packets dialog was created.
This commit is contained in:
parent
f725bbef5e
commit
ea2ddd40f5
|
@ -1224,13 +1224,13 @@ void LogwolfMainWindow::mergeCaptureFile()
|
|||
}
|
||||
|
||||
for (;;) {
|
||||
CaptureFileDialog merge_dlg(this, capture_file_.capFile(), read_filter);
|
||||
CaptureFileDialog merge_dlg(this, capture_file_.capFile());
|
||||
int file_type;
|
||||
cf_status_t merge_status;
|
||||
char *in_filenames[2];
|
||||
char *tmpname;
|
||||
|
||||
if (merge_dlg.merge(file_name)) {
|
||||
if (merge_dlg.merge(file_name, read_filter)) {
|
||||
gchar *err_msg;
|
||||
|
||||
if (!dfilter_compile(qUtf8Printable(read_filter), &rfcode, &err_msg)) {
|
||||
|
|
|
@ -172,9 +172,9 @@ bool LogwolfMainWindow::openCaptureFile(QString cf_path, QString read_filter, un
|
|||
for (;;) {
|
||||
|
||||
if (cf_path.isEmpty()) {
|
||||
CaptureFileDialog open_dlg(this, capture_file_.capFile(), read_filter);
|
||||
CaptureFileDialog open_dlg(this, capture_file_.capFile());
|
||||
|
||||
if (open_dlg.open(file_name, type)) {
|
||||
if (open_dlg.open(file_name, type, read_filter)) {
|
||||
cf_path = file_name;
|
||||
} else {
|
||||
ret = false;
|
||||
|
|
|
@ -49,10 +49,9 @@
|
|||
#include <ui/qt/utils/qt_ui_utils.h>
|
||||
#include <main_application.h>
|
||||
|
||||
CaptureFileDialog::CaptureFileDialog(QWidget *parent, capture_file *cf, QString &display_filter) :
|
||||
CaptureFileDialog::CaptureFileDialog(QWidget *parent, capture_file *cf) :
|
||||
WiresharkFileDialog(parent),
|
||||
cap_file_(cf),
|
||||
display_filter_(display_filter),
|
||||
#if !defined(Q_OS_WIN)
|
||||
display_filter_edit_(NULL),
|
||||
default_ft_(-1),
|
||||
|
@ -274,16 +273,16 @@ wtap_compression_type CaptureFileDialog::compressionType() {
|
|||
return compression_type_;
|
||||
}
|
||||
|
||||
int CaptureFileDialog::open(QString &file_name, unsigned int &type) {
|
||||
int CaptureFileDialog::open(QString &file_name, unsigned int &type, QString &display_filter) {
|
||||
QString title_str = mainApp->windowTitleString(tr("Open Capture File"));
|
||||
GString *fname = g_string_new(file_name.toUtf8().constData());
|
||||
GString *dfilter = g_string_new(display_filter_.toUtf8().constData());
|
||||
GString *dfilter = g_string_new(display_filter.toUtf8().constData());
|
||||
gboolean wof_status;
|
||||
|
||||
// XXX Add a widget->HWND routine to qt_ui_utils and use it instead.
|
||||
wof_status = win32_open_file((HWND)parentWidget()->effectiveWinId(), title_str.toStdWString().c_str(), fname, &type, dfilter);
|
||||
file_name = fname->str;
|
||||
display_filter_ = dfilter->str;
|
||||
display_filter = dfilter->str;
|
||||
|
||||
g_string_free(fname, TRUE);
|
||||
g_string_free(dfilter, TRUE);
|
||||
|
@ -330,16 +329,16 @@ check_savability_t CaptureFileDialog::exportSelectedPackets(QString &file_name,
|
|||
return CANCELLED;
|
||||
}
|
||||
|
||||
int CaptureFileDialog::merge(QString &file_name) {
|
||||
int CaptureFileDialog::merge(QString &file_name, QString &display_filter) {
|
||||
QString title_str = mainApp->windowTitleString(tr("Merge Capture File"));
|
||||
GString *fname = g_string_new(file_name.toUtf8().constData());
|
||||
GString *dfilter = g_string_new(display_filter_.toUtf8().constData());
|
||||
GString *dfilter = g_string_new(display_filter.toUtf8().constData());
|
||||
gboolean wmf_status;
|
||||
|
||||
|
||||
wmf_status = win32_merge_file((HWND)parentWidget()->effectiveWinId(), title_str.toStdWString().c_str(), fname, dfilter, &merge_type_);
|
||||
file_name = fname->str;
|
||||
display_filter_ = dfilter->str;
|
||||
display_filter = dfilter->str;
|
||||
|
||||
g_string_free(fname, TRUE);
|
||||
g_string_free(dfilter, TRUE);
|
||||
|
@ -634,13 +633,13 @@ wtap_compression_type CaptureFileDialog::compressionType() {
|
|||
return compress_.isChecked() ? WTAP_GZIP_COMPRESSED : WTAP_UNCOMPRESSED;
|
||||
}
|
||||
|
||||
void CaptureFileDialog::addDisplayFilterEdit() {
|
||||
void CaptureFileDialog::addDisplayFilterEdit(QString &display_filter) {
|
||||
QGridLayout *fd_grid = qobject_cast<QGridLayout*>(layout());
|
||||
|
||||
fd_grid->addWidget(new QLabel(tr("Read filter:")), last_row_, 0);
|
||||
|
||||
display_filter_edit_ = new DisplayFilterEdit(this, ReadFilterToApply);
|
||||
display_filter_edit_->setText(display_filter_);
|
||||
display_filter_edit_->setText(display_filter);
|
||||
fd_grid->addWidget(display_filter_edit_, last_row_, 1);
|
||||
last_row_++;
|
||||
}
|
||||
|
@ -699,20 +698,20 @@ QDialogButtonBox *CaptureFileDialog::addHelpButton(topic_action_e help_topic)
|
|||
return button_box;
|
||||
}
|
||||
|
||||
int CaptureFileDialog::open(QString &file_name, unsigned int &type) {
|
||||
int CaptureFileDialog::open(QString &file_name, unsigned int &type, QString &display_filter) {
|
||||
setWindowTitle(mainApp->windowTitleString(tr("Open Capture File")));
|
||||
setNameFilters(buildFileOpenTypeList());
|
||||
setFileMode(QFileDialog::ExistingFile);
|
||||
|
||||
addFormatTypeSelector(left_v_box_);
|
||||
addDisplayFilterEdit();
|
||||
addDisplayFilterEdit(display_filter);
|
||||
addPreview(right_v_box_);
|
||||
addHelpButton(HELP_OPEN_DIALOG);
|
||||
|
||||
// Grow the dialog to account for the extra widgets.
|
||||
resize(width(), height() + left_v_box_.minimumSize().height() + display_filter_edit_->minimumSize().height());
|
||||
|
||||
display_filter_.clear();
|
||||
display_filter.clear();
|
||||
|
||||
if (!file_name.isEmpty()) {
|
||||
selectFile(file_name);
|
||||
|
@ -721,7 +720,7 @@ int CaptureFileDialog::open(QString &file_name, unsigned int &type) {
|
|||
if (WiresharkFileDialog::exec() && selectedFiles().length() > 0) {
|
||||
file_name = selectedFiles()[0];
|
||||
type = open_info_name_to_type(qPrintable(format_type_.currentText()));
|
||||
display_filter_.append(display_filter_edit_->text());
|
||||
display_filter.append(display_filter_edit_->text());
|
||||
|
||||
return QDialog::Accepted;
|
||||
} else {
|
||||
|
@ -820,25 +819,25 @@ check_savability_t CaptureFileDialog::exportSelectedPackets(QString &file_name,
|
|||
return CANCELLED;
|
||||
}
|
||||
|
||||
int CaptureFileDialog::merge(QString &file_name) {
|
||||
int CaptureFileDialog::merge(QString &file_name, QString &display_filter) {
|
||||
setWindowTitle(mainApp->windowTitleString(tr("Merge Capture File")));
|
||||
setNameFilters(buildFileOpenTypeList());
|
||||
setFileMode(QFileDialog::ExistingFile);
|
||||
|
||||
addDisplayFilterEdit();
|
||||
addDisplayFilterEdit(display_filter);
|
||||
addMergeControls(left_v_box_);
|
||||
addPreview(right_v_box_);
|
||||
addHelpButton(HELP_MERGE_DIALOG);
|
||||
|
||||
file_name.clear();
|
||||
display_filter_.clear();
|
||||
display_filter.clear();
|
||||
|
||||
// Grow the dialog to account for the extra widgets.
|
||||
resize(width(), height() + right_v_box_.minimumSize().height() + display_filter_edit_->minimumSize().height());
|
||||
|
||||
if (WiresharkFileDialog::exec() && selectedFiles().length() > 0) {
|
||||
file_name.append(selectedFiles()[0]);
|
||||
display_filter_.append(display_filter_edit_->text());
|
||||
display_filter.append(display_filter_edit_->text());
|
||||
|
||||
return QDialog::Accepted;
|
||||
} else {
|
||||
|
|
|
@ -60,7 +60,7 @@ class CaptureFileDialog : public WiresharkFileDialog
|
|||
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CaptureFileDialog(QWidget *parent = NULL, capture_file *cf = NULL, QString &display_filter = *new QString());
|
||||
explicit CaptureFileDialog(QWidget *parent = NULL, capture_file *cf = NULL);
|
||||
static check_savability_t checkSaveAsWithComments(QWidget *
|
||||
#if defined(Q_OS_WIN)
|
||||
parent
|
||||
|
@ -73,12 +73,11 @@ public:
|
|||
|
||||
private:
|
||||
capture_file *cap_file_;
|
||||
QString &display_filter_;
|
||||
|
||||
#if !defined(Q_OS_WIN)
|
||||
void addMergeControls(QVBoxLayout &v_box);
|
||||
void addFormatTypeSelector(QVBoxLayout &v_box);
|
||||
void addDisplayFilterEdit();
|
||||
void addDisplayFilterEdit(QString &display_filter);
|
||||
void addPreview(QVBoxLayout &v_box);
|
||||
QString fileExtensionType(int et, bool extension_globs = true);
|
||||
QString fileType(int ft, QStringList &suffixes);
|
||||
|
@ -131,10 +130,10 @@ public slots:
|
|||
void accept() Q_DECL_OVERRIDE;
|
||||
#endif
|
||||
int exec() Q_DECL_OVERRIDE;
|
||||
int open(QString &file_name, unsigned int &type);
|
||||
int open(QString &file_name, unsigned int &type, QString &display_filter);
|
||||
check_savability_t saveAs(QString &file_name, bool must_support_comments);
|
||||
check_savability_t exportSelectedPackets(QString &file_name, packet_range_t *range, QString selRange = QString());
|
||||
int merge(QString &file_name);
|
||||
int merge(QString &file_name, QString &display_filter);
|
||||
|
||||
private slots:
|
||||
#if !defined(Q_OS_WIN)
|
||||
|
|
|
@ -1255,13 +1255,13 @@ void WiresharkMainWindow::mergeCaptureFile()
|
|||
}
|
||||
|
||||
for (;;) {
|
||||
CaptureFileDialog merge_dlg(this, capture_file_.capFile(), read_filter);
|
||||
CaptureFileDialog merge_dlg(this, capture_file_.capFile());
|
||||
int file_type;
|
||||
cf_status_t merge_status;
|
||||
char *in_filenames[2];
|
||||
char *tmpname;
|
||||
|
||||
if (merge_dlg.merge(file_name)) {
|
||||
if (merge_dlg.merge(file_name, read_filter)) {
|
||||
gchar *err_msg;
|
||||
|
||||
if (!dfilter_compile(qUtf8Printable(read_filter), &rfcode, &err_msg)) {
|
||||
|
|
|
@ -199,9 +199,9 @@ bool WiresharkMainWindow::openCaptureFile(QString cf_path, QString read_filter,
|
|||
for (;;) {
|
||||
|
||||
if (cf_path.isEmpty()) {
|
||||
CaptureFileDialog open_dlg(this, capture_file_.capFile(), read_filter);
|
||||
CaptureFileDialog open_dlg(this, capture_file_.capFile());
|
||||
|
||||
if (open_dlg.open(file_name, type)) {
|
||||
if (open_dlg.open(file_name, type, read_filter)) {
|
||||
cf_path = file_name;
|
||||
} else {
|
||||
ret = false;
|
||||
|
|
Loading…
Reference in New Issue