diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2017-09-26 10:40:36 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2017-09-26 10:46:55 +0200 |
commit | 4c36bd42d4fcbb13f7349bd50130dbc6bbf8597a (patch) | |
tree | 6e3ae390a00e1192c20421d727b123ed7a584245 | |
parent | 1e318bec54da3f37901eadb2a04a4520737eb9a0 (diff) |
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.
-rw-r--r-- | plugins/huawei/mm-broadband-modem-huawei.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/plugins/huawei/mm-broadband-modem-huawei.c b/plugins/huawei/mm-broadband-modem-huawei.c index d3f11b55..3d743675 100644 --- a/plugins/huawei/mm-broadband-modem-huawei.c +++ b/plugins/huawei/mm-broadband-modem-huawei.c @@ -2197,6 +2197,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_kernel_device_get_parent_sysfs_path (mm_port_peek_kernel_device (port)); @@ -2210,16 +2211,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_kernel_device_get_parent_sysfs_path (mm_port_peek_kernel_device (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; } |