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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user