Qt: Do not redissect packets before sorting

There's no need to perform redissection as we are sorting data already
present in PacketListRecord.

This change is not only improving performance, but prevents a crash
related to "event interruptions". As wsApp->processEvents() is called
with QEventLoop::AllEvents, it is possible for user to trigger any
action. If the user decided to close the file while packets are being
redissected inside PacketListModel::sort(), Wireshark would crash.

Ping-Bug: 16097
Change-Id: I82eee0efc789a1102e5fbe3670ed79039a18b8be
Reviewed-on: https://code.wireshark.org/review/34679
Reviewed-by: Roland Knall <rknall@gmail.com>
Petri-Dish: Roland Knall <rknall@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Tomasz Moń 2019-10-02 19:25:12 +02:00 committed by Anders Broman
parent 9e686f1e43
commit e7f5ba6aa7
1 changed files with 1 additions and 23 deletions

View File

@ -352,7 +352,6 @@ QElapsedTimer busy_timer_;
const int busy_timeout_ = 65; // ms, approximately 15 fps
void PacketListModel::sort(int column, Qt::SortOrder order)
{
// packet_list_store.c:packet_list_dissect_and_cache_all
if (!cap_file_ || visible_rows_.count() < 1) return;
if (column < 0) return;
@ -361,29 +360,8 @@ void PacketListModel::sort(int column, Qt::SortOrder order)
sort_order_ = order;
sort_cap_file_ = cap_file_;
gboolean stop_flag = FALSE;
QString col_title = get_column_title(column);
busy_timer_.start();
emit pushProgressStatus(tr("Dissecting"), true, true, &stop_flag);
int row_num = 0;
foreach (PacketListRecord *row, physical_rows_) {
row->columnString(sort_cap_file_, column);
row_num++;
if (busy_timer_.elapsed() > busy_timeout_) {
if (stop_flag) {
emit popProgressStatus();
return;
}
emit updateProgressStatus(row_num * 100 / physical_rows_.count());
// What's the least amount of processing that we can do which will draw
// the progress indicator?
wsApp->processEvents(QEventLoop::AllEvents, 1);
busy_timer_.restart();
}
}
emit popProgressStatus();
// XXX Use updateProgress instead. We'd have to switch from std::sort to
// something we can interrupt.
if (!col_title.isEmpty()) {
@ -391,7 +369,7 @@ void PacketListModel::sort(int column, Qt::SortOrder order)
emit pushBusyStatus(busy_msg);
}
busy_timer_.restart();
busy_timer_.start();
sort_column_is_numeric_ = isNumericColumn(sort_column_);
std::sort(physical_rows_.begin(), physical_rows_.end(), recordLessThan);