diff options
author | Mikael Kanstrup <mikael.kanstrup@gmail.com> | 2017-08-24 16:16:34 +0200 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2017-08-28 14:41:43 +0000 |
commit | 8873c7e494018637449a17a7f7ddaf88ad43f3c6 (patch) | |
tree | 162c283b967e7dc5f98a54575ff2ed25444997a8 /ui/qt/extcap_options_dialog.cpp | |
parent | 76c231bd683410bed4fa803bcbc91e613e201ab0 (diff) |
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 <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'ui/qt/extcap_options_dialog.cpp')
-rw-r--r-- | ui/qt/extcap_options_dialog.cpp | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/ui/qt/extcap_options_dialog.cpp b/ui/qt/extcap_options_dialog.cpp index 99e9b5743c..c70f5531bb 100644 --- a/ui/qt/extcap_options_dialog.cpp +++ b/ui/qt/extcap_options_dialog.cpp @@ -83,7 +83,7 @@ ExtcapOptionsDialog::ExtcapOptionsDialog(QWidget *parent) : ExtcapOptionsDialog * ExtcapOptionsDialog::createForDevice(QString &dev_name, QWidget *parent) { - interface_t device; + interface_t *device; ExtcapOptionsDialog * resultDialog = NULL; bool dev_found = false; guint if_idx; @@ -93,8 +93,8 @@ ExtcapOptionsDialog * ExtcapOptionsDialog::createForDevice(QString &dev_name, QW for (if_idx = 0; if_idx < global_capture_opts.all_ifaces->len; if_idx++) { - device = g_array_index(global_capture_opts.all_ifaces, interface_t, if_idx); - if (dev_name.compare(QString(device.name)) == 0 && device.if_info.type == IF_EXTCAP) + device = &g_array_index(global_capture_opts.all_ifaces, interface_t, if_idx); + if (dev_name.compare(QString(device->name)) == 0 && device->if_info.type == IF_EXTCAP) { dev_found = true; break; @@ -108,7 +108,7 @@ ExtcapOptionsDialog * ExtcapOptionsDialog::createForDevice(QString &dev_name, QW resultDialog->device_name = QString(dev_name); resultDialog->device_idx = if_idx; - resultDialog->setWindowTitle(wsApp->windowTitleString(tr("Interface Options") + ": " + device.display_name)); + resultDialog->setWindowTitle(wsApp->windowTitleString(tr("Interface Options") + ": " + device->display_name)); resultDialog->updateWidgets(); @@ -316,11 +316,11 @@ void ExtcapOptionsDialog::on_buttonBox_rejected() void ExtcapOptionsDialog::on_buttonBox_helpRequested() { - interface_t device; + interface_t *device; QString interface_help = NULL; - device = g_array_index(global_capture_opts.all_ifaces, interface_t, device_idx); - interface_help = QString(extcap_get_help_for_ifname(device.name)); + device = &g_array_index(global_capture_opts.all_ifaces, interface_t, device_idx); + interface_help = QString(extcap_get_help_for_ifname(device->name)); /* The extcap interface didn't provide an help. Let's go with the default */ if (interface_help.isEmpty()) { wsApp->helpTopicAction(HELP_EXTCAP_OPTIONS_DIALOG); @@ -343,7 +343,7 @@ void ExtcapOptionsDialog::on_buttonBox_helpRequested() { QMessageBox::warning(this, tr("Extcap Help cannot be found"), QString(tr("The help for the extcap interface %1 cannot be found. Given file: %2")) - .arg(device.name).arg(help_url.path()), + .arg(device->name).arg(help_url.path()), QMessageBox::Ok); } @@ -352,11 +352,9 @@ void ExtcapOptionsDialog::on_buttonBox_helpRequested() bool ExtcapOptionsDialog::saveOptionToCaptureInfo() { GHashTable * ret_args; - interface_t device; - - device = g_array_index(global_capture_opts.all_ifaces, interface_t, device_idx); - global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, device_idx); + interface_t *device; + device = &g_array_index(global_capture_opts.all_ifaces, interface_t, device_idx); ret_args = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); ExtcapArgumentList::const_iterator iter; @@ -381,12 +379,9 @@ bool ExtcapOptionsDialog::saveOptionToCaptureInfo() g_hash_table_insert(ret_args, call_string, value_string ); } - if (device.external_cap_args_settings != NULL) - g_hash_table_unref(device.external_cap_args_settings); - device.external_cap_args_settings = ret_args; - - g_array_insert_val(global_capture_opts.all_ifaces, device_idx, device); - + if (device->external_cap_args_settings != NULL) + g_hash_table_unref(device->external_cap_args_settings); + device->external_cap_args_settings = ret_args; return true; } |