From ee1e9afb8fbb67342a86b5c5f8f27a33797913a2 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 26 Sep 2017 10:40:36 +0200 Subject: huawei: plug memleak when listing cdc-wdm AT ports The returned list contains full references, so make sure we unref them before going on. Note that it's ok to return a pointer to one object inside this list even if we're unref-ing them all, because we're sure that the caller knows it's peek-ing a port object. (cherry picked from commit 4c36bd42d4fcbb13f7349bd50130dbc6bbf8597a) --- plugins/huawei/mm-broadband-modem-huawei.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/huawei/mm-broadband-modem-huawei.c b/plugins/huawei/mm-broadband-modem-huawei.c index 2d82908c1..9ce91ca66 100644 --- a/plugins/huawei/mm-broadband-modem-huawei.c +++ b/plugins/huawei/mm-broadband-modem-huawei.c @@ -2308,6 +2308,7 @@ peek_port_at_for_data (MMBroadbandModemHuawei *self, { GList *cdc_wdm_at_ports, *l; const gchar *net_port_parent_path; + MMPortSerialAt *found = NULL; g_warn_if_fail (mm_port_get_subsys (port) == MM_PORT_SUBSYS_NET); net_port_parent_path = mm_port_get_parent_path (port); @@ -2321,16 +2322,17 @@ peek_port_at_for_data (MMBroadbandModemHuawei *self, MM_PORT_SUBSYS_USB, MM_PORT_TYPE_AT, NULL); - for (l = cdc_wdm_at_ports; l; l = g_list_next (l)) { + for (l = cdc_wdm_at_ports; l && !found; l = g_list_next (l)) { const gchar *wdm_port_parent_path; g_assert (MM_IS_PORT_SERIAL_AT (l->data)); wdm_port_parent_path = mm_port_get_parent_path (MM_PORT (l->data)); if (wdm_port_parent_path && g_str_equal (wdm_port_parent_path, net_port_parent_path)) - return MM_PORT_SERIAL_AT (l->data); + found = MM_PORT_SERIAL_AT (l->data); } - return NULL; + g_list_free_full (cdc_wdm_at_ports, g_object_unref); + return found; } -- cgit v1.2.1