aboutsummaryrefslogtreecommitdiffstats
path: root/capture_opts.c
diff options
context:
space:
mode:
authorMikael Kanstrup <mikael.kanstrup@gmail.com>2015-11-26 09:27:51 +0100
committerPeter Wu <peter@lekensteyn.nl>2015-12-11 10:38:32 +0000
commit3120d1f8012377820dbc011713377ff9daab5f5c (patch)
tree4f273c31785b3db85d5c917888d7b2dde35b46a2 /capture_opts.c
parentf142595db72955260976d4257592032bef7d492a (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 'capture_opts.c')
-rw-r--r--capture_opts.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/capture_opts.c b/capture_opts.c
index 5c6042167e..c2c25d1009 100644
--- a/capture_opts.c
+++ b/capture_opts.c
@@ -1146,6 +1146,50 @@ collect_ifaces(capture_options *capture_opts)
}
}
+static void
+capture_opts_free_interface_t_links(gpointer elem, gpointer unused _U_)
+{
+ link_row* e = (link_row*)elem;
+ if (e != NULL)
+ g_free(e->name);
+ g_free(elem);
+}
+
+static void
+capture_opts_free_interface_t_addrs(gpointer elem, gpointer unused _U_)
+{
+ g_free(elem);
+}
+
+void
+capture_opts_free_interface_t(interface_t *device)
+{
+ if (device != NULL) {
+ g_free(device->name);
+ g_free(device->display_name);
+ g_free(device->friendly_name);
+ g_free(device->addresses);
+ g_free(device->cfilter);
+ g_list_foreach(device->links,
+ capture_opts_free_interface_t_links, NULL);
+ g_list_free(device->links);
+#ifdef HAVE_PCAP_REMOTE
+ g_free(device->remote_opts.remote_host_opts.remote_host);
+ g_free(device->remote_opts.remote_host_opts.remote_port);
+ g_free(device->remote_opts.remote_host_opts.auth_username);
+ g_free(device->remote_opts.remote_host_opts.auth_password);
+#endif
+ g_free(device->if_info.name);
+ g_free(device->if_info.friendly_name);
+ g_free(device->if_info.vendor_description);
+ g_slist_foreach(device->if_info.addrs,
+ capture_opts_free_interface_t_addrs, NULL);
+ g_slist_free(device->if_info.addrs);
+#ifdef HAVE_EXTCAP
+ g_free(device->if_info.extcap);
+#endif
+ }
+}
#endif /* HAVE_LIBPCAP */