diff options
author | Mikael Kanstrup <mikael.kanstrup@gmail.com> | 2015-11-26 09:27:51 +0100 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2015-12-11 10:38:32 +0000 |
commit | 3120d1f8012377820dbc011713377ff9daab5f5c (patch) | |
tree | 4f273c31785b3db85d5c917888d7b2dde35b46a2 /ui/qt | |
parent | f142595db72955260976d4257592032bef7d492a (diff) |
Fix memory leaks in all_ifaces when interface list changes
Valgrind report leaks of several allocations like these:
590 bytes in 50 blocks are possibly lost in loss record 29,818 of 31,670
at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0xCB9C8A7: __vasprintf_chk (vasprintf_chk.c:82)
by 0xA3D8DCA: g_vasprintf (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.4)
by 0xA3B846C: g_strdup_vprintf (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.4)
by 0xA3B850B: g_strdup_printf (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.4)
by 0x6F4B51: scan_local_interfaces (iface_lists.c:254)
by 0x6EF3D8: iface_mon_handler2 (iface_monitor.c:113)
by 0xBE56F1D: ??? (in /lib/libnl-3.so.200.3.0)
by 0xBA16F19: ??? (in /usr/lib/libnl-route-3.so.200.3.0)
by 0xBE54E5E: nl_cache_parse (in /lib/libnl-3.so.200.3.0)
by 0xBE585CA: nl_msg_parse (in /lib/libnl-3.so.200.3.0)
by 0x6EF372: iface_mon_handler (iface_monitor.c:123)
When the list of network interfaces is updated allocations done
for global_capture_opts.all_ifaces elements leak memory. Fixed by
introducing a helper function to be used for removing an interface_t
element from all_ifaces array. While at it also fixed misc leaks when
updating individual allocated records of all_ifaces elements.
Change-Id: I035e6936a44edeef2ebe4780931c14cde99e93a4
Reviewed-on: https://code.wireshark.org/review/12209
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Diffstat (limited to 'ui/qt')
-rw-r--r-- | ui/qt/capture_filter_edit.cpp | 1 | ||||
-rw-r--r-- | ui/qt/capture_interfaces_dialog.cpp | 1 | ||||
-rw-r--r-- | ui/qt/interface_tree.cpp | 12 | ||||
-rw-r--r-- | ui/qt/manage_interfaces_dialog.cpp | 3 |
4 files changed, 9 insertions, 8 deletions
diff --git a/ui/qt/capture_filter_edit.cpp b/ui/qt/capture_filter_edit.cpp index 02ced86f50..99b8fa8e48 100644 --- a/ui/qt/capture_filter_edit.cpp +++ b/ui/qt/capture_filter_edit.cpp @@ -344,6 +344,7 @@ void CaptureFilterEdit::setFilterSyntaxState(QString filter, bool valid, QString // continue; /* Programming error: somehow managed to select an "unsupported" entry */ // } g_array_remove_index(global_capture_opts.all_ifaces, i); + g_free(device.cfilter); device.cfilter = qstring_strdup(filter); g_array_insert_val(global_capture_opts.all_ifaces, i, device); // update_filter_string(device.name, filter_text); diff --git a/ui/qt/capture_interfaces_dialog.cpp b/ui/qt/capture_interfaces_dialog.cpp index 7f139890e6..949b2128d8 100644 --- a/ui/qt/capture_interfaces_dialog.cpp +++ b/ui/qt/capture_interfaces_dialog.cpp @@ -538,6 +538,7 @@ void CaptureInterfacesDialog::updateInterfaces() #endif gchar* prefFilter = capture_dev_user_cfilter_find(device->name); if (prefFilter) { + g_free(device->cfilter); device->cfilter = prefFilter; } ti->setText(col_filter_, device->cfilter); diff --git a/ui/qt/interface_tree.cpp b/ui/qt/interface_tree.cpp index feff96e284..9d6554a276 100644 --- a/ui/qt/interface_tree.cpp +++ b/ui/qt/interface_tree.cpp @@ -361,21 +361,17 @@ void InterfaceTree::updateSelectedInterfaces() void InterfaceTree::setSelectedInterfaces() { #ifdef HAVE_LIBPCAP - interface_t device; + interface_t *device; QTreeWidgetItemIterator iter(this); while (*iter) { QString device_name = (*iter)->data(IFTREE_COL_NAME, Qt::UserRole).value<QString>(); for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) { - device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); - if (device_name.compare(QString().fromUtf8(device.name)) == 0) { - (*iter)->setSelected(device.selected); - global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i); - g_array_insert_val(global_capture_opts.all_ifaces, i, device); + device = &g_array_index(global_capture_opts.all_ifaces, interface_t, i); + if (device_name.compare(QString().fromUtf8(device->name)) == 0) { + (*iter)->setSelected(device->selected); break; } - global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i); - g_array_insert_val(global_capture_opts.all_ifaces, i, device); } iter++; } diff --git a/ui/qt/manage_interfaces_dialog.cpp b/ui/qt/manage_interfaces_dialog.cpp index 89feac1621..ef216b1f80 100644 --- a/ui/qt/manage_interfaces_dialog.cpp +++ b/ui/qt/manage_interfaces_dialog.cpp @@ -238,6 +238,7 @@ void ManageInterfacesDialog::pipeAccepted() continue; } global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i); + capture_opts_free_interface_t(&device); } // Next rebuild a fresh list @@ -259,6 +260,7 @@ void ManageInterfacesDialog::pipeAccepted() } } + memset(&device, 0, sizeof(device)); device.name = qstring_strdup(pipe_name); device.display_name = g_strdup(device.name); device.hidden = FALSE; @@ -506,6 +508,7 @@ void ManageInterfacesDialog::addRemoteInterfaces(GList* rlist, remote_options *r ip_str = g_string_new(""); str = ""; ips = 0; + memset(&device, 0, sizeof(device)); device.name = g_strdup(if_info->name); /* Is this interface hidden and, if so, should we include it anyway? */ |