From 8873c7e494018637449a17a7f7ddaf88ad43f3c6 Mon Sep 17 00:00:00 2001 From: Mikael Kanstrup Date: Thu, 24 Aug 2017 16:16:34 +0200 Subject: iface_lists: Access all_ifaces member by reference Change access of all_ifaces elements from by val to by reference. With this change unnecessary copying of the whole struct is avoided but even more important is that elements no longer have to be removed and inserted whenever data is updated. This change aims to make it more clear that all_ifaces elements shall never be removed from the array without freeing resources via the capture_opts_free_interface_t function. NOTE: Code for GTK UI not updated Ping-Bug: 13864 Change-Id: I36742cb1d5c8daa136c9d3732a044a7c8e5c7fe7 Reviewed-on: https://code.wireshark.org/review/23201 Petri-Dish: Anders Broman Tested-by: Petri Dish Buildbot Reviewed-by: Peter Wu Reviewed-by: Anders Broman --- ui/qt/interface_toolbar.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'ui/qt/interface_toolbar.cpp') diff --git a/ui/qt/interface_toolbar.cpp b/ui/qt/interface_toolbar.cpp index ffddf28f50..fed9cb919b 100644 --- a/ui/qt/interface_toolbar.cpp +++ b/ui/qt/interface_toolbar.cpp @@ -951,20 +951,20 @@ void InterfaceToolbar::interfaceListChanged() for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) { - interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); - if (device.hidden) + interface_t *device = &g_array_index(global_capture_opts.all_ifaces, interface_t, i); + if (device->hidden) continue; - if (interface_.keys().contains(device.name)) + if (interface_.keys().contains(device->name)) { - ui->interfacesComboBox->addItem(device.name); - if (selected_ifname.compare(device.name) == 0) + ui->interfacesComboBox->addItem(device->name); + if (selected_ifname.compare(device->name) == 0) { // Keep selected interface #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - ui->interfacesComboBox->setCurrentText(device.name); + ui->interfacesComboBox->setCurrentText(device->name); #else - int new_index = ui->interfacesComboBox->findText(device.name); + int new_index = ui->interfacesComboBox->findText(device->name); if (new_index >= 0) { ui->interfacesComboBox->setCurrentIndex(new_index); -- cgit v1.2.3