From 770ac9123b9c74e2325b39c5af04455dd14f2aba Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Sun, 22 Feb 2015 14:56:38 -0800 Subject: [PATCH] Qt: Fix a crash when changing the layout. Freeze and thaw the packet list when changing the layout. This has the side effect of clearing the proto tree and byte view, which avoids reading a bad tvb pointer. Note that we might want to add a cleanup callback to free_data_sources. Save and restore the current row. Add CaptureFile::currentRow. Fix a couple of comparisons in PacketList. Change-Id: I26f9b97ae5a7cdb4fb6e5e6e675570884900e995 Reviewed-on: https://code.wireshark.org/review/7337 Reviewed-by: Gerald Combs --- ui/qt/byte_view_tab.cpp | 4 ++++ ui/qt/capture_file.cpp | 7 +++++++ ui/qt/capture_file.h | 7 +++++++ ui/qt/main_window_slots.cpp | 7 ++++--- ui/qt/packet_list.cpp | 4 ++-- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/ui/qt/byte_view_tab.cpp b/ui/qt/byte_view_tab.cpp index 4df8cb39a7..3b2c138cfd 100644 --- a/ui/qt/byte_view_tab.cpp +++ b/ui/qt/byte_view_tab.cpp @@ -24,6 +24,10 @@ #include #include +// To do: +// - We might want to add a callback to free_data_sources in so that we +// don't have to blindly call clear(). + ByteViewTab::ByteViewTab(QWidget *parent) : QTabWidget(parent) { diff --git a/ui/qt/capture_file.cpp b/ui/qt/capture_file.cpp index ed05ea9b04..a32f225f15 100644 --- a/ui/qt/capture_file.cpp +++ b/ui/qt/capture_file.cpp @@ -68,6 +68,13 @@ bool CaptureFile::isValid() const return false; } +int CaptureFile::currentRow() +{ + if (isValid()) + return cap_file_->current_row; + return -1; +} + void CaptureFile::retapPackets() { if (cap_file_) { diff --git a/ui/qt/capture_file.h b/ui/qt/capture_file.h index 3a4742e312..ace854d0d8 100644 --- a/ui/qt/capture_file.h +++ b/ui/qt/capture_file.h @@ -47,6 +47,13 @@ public: */ bool isValid() const; + /** Get the current selected row + * + * @return the current selected index of the packet list if the capture + * file is open and a packet is selected, otherwise -1. + */ + int currentRow(); + /** Return a filename suitable for use in a window title. * * @return One of: the basename of the capture file without an extension, diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp index 2b09f2facf..b7ccae4cd4 100644 --- a/ui/qt/main_window_slots.cpp +++ b/ui/qt/main_window_slots.cpp @@ -255,9 +255,11 @@ void MainWindow::layoutPanes() if (cur_layout_ == new_layout) return; QSplitter *parents[3]; + int current_row = capture_file_.currentRow(); // Reparent all widgets and add them back in the proper order below. // This hides each widget as well. + packet_list_->freeze(); // Clears tree and byte view tab. packet_list_->setParent(main_ui_->mainStack); proto_tree_->setParent(main_ui_->mainStack); byte_view_tab_->setParent(main_ui_->mainStack); @@ -341,9 +343,8 @@ void MainWindow::layoutPanes() } widget->setVisible(show); } - if (capture_file_.isValid() && capture_file_.capFile()->current_row >= 0) { - cf_select_packet(capture_file_.capFile(), capture_file_.capFile()->current_row); - } + packet_list_->thaw(); + cf_select_packet(capture_file_.capFile(), current_row); // XXX Doesn't work for row 0? cur_layout_ = new_layout; } diff --git a/ui/qt/packet_list.cpp b/ui/qt/packet_list.cpp index d2a9e7ef80..6b5a70b11c 100644 --- a/ui/qt/packet_list.cpp +++ b/ui/qt/packet_list.cpp @@ -639,7 +639,7 @@ void PacketList::redrawVisiblePackets() { build_column_format_array(&cap_file_->cinfo, prefs.num_cols, FALSE); packet_list_model_->resetColumns(); - if (row > 0) { + if (row >= 0) { setCurrentIndex(packet_list_model_->index(row, 0)); } @@ -880,7 +880,7 @@ void PacketList::goLastPacket(void) { // XXX We can jump to the wrong packet if a display filter is applied void PacketList::goToPacket(int packet) { int row = packet_list_model_->packetNumberToRow(packet); - if (row > 0) { + if (row >= 0) { setCurrentIndex(packet_list_model_->index(row, 0)); } }