base-modem: plug memleaks when building port lists

The mm_base_modem_find_ports() method builds a list of full
references, so we need to unref them in the peek() methods.

    ==10047== 14,959 (24 direct, 14,935 indirect) bytes in 1 blocks are definitely lost in loss record 5,470 of 5,473
    ==10047==    at 0x4C2CE5F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    ==10047==    by 0x66E3028: g_malloc (in /usr/lib/libglib-2.0.so.0.5200.3)
    ==10047==    by 0x66FAB25: g_slice_alloc (in /usr/lib/libglib-2.0.so.0.5200.3)
    ==10047==    by 0x66D9A33: g_list_append (in /usr/lib/libglib-2.0.so.0.5200.3)
    ==10047==    by 0x15F6A7: mm_base_modem_find_ports (mm-base-modem.c:845)
    ==10047==    by 0x15E9F3: mm_base_modem_peek_port_qmi_for_data (mm-base-modem.c:579)
    ==10047==    by 0x15E8FC: mm_base_modem_get_port_qmi_for_data (mm-base-modem.c:555)
    ==10047==    by 0x1BB99F: _connect (mm-bearer-qmi.c:1391)
    ==10047==    by 0x1540B4: mm_base_bearer_connect (mm-base-bearer.c:841)
    ==10047==    by 0x181F4F: connection_step (mm-iface-modem-simple.c:597)
    ==10047==    by 0x181321: create_bearer_ready (mm-iface-modem-simple.c:258)
    ==10047==    by 0x612FD52: ??? (in /usr/lib/libgio-2.0.so.0.5200.3)
This commit is contained in:
Aleksander Morgado
2017-10-07 14:06:06 +02:00
parent 882f6b04d6
commit 58e6f652a1

View File

@@ -563,6 +563,7 @@ mm_base_modem_peek_port_qmi_for_data (MMBaseModem *self,
{
GList *cdc_wdm_qmi_ports, *l;
const gchar *net_port_parent_path;
MMPortQmi *found = NULL;
g_warn_if_fail (mm_port_get_subsys (data) == MM_PORT_SUBSYS_NET);
net_port_parent_path = mm_kernel_device_get_parent_sysfs_path (mm_port_peek_kernel_device (data));
@@ -580,21 +581,25 @@ mm_base_modem_peek_port_qmi_for_data (MMBaseModem *self,
MM_PORT_SUBSYS_USB,
MM_PORT_TYPE_QMI,
NULL);
for (l = cdc_wdm_qmi_ports; l; l = g_list_next (l)) {
for (l = cdc_wdm_qmi_ports; l && !found; l = g_list_next (l)) {
const gchar *wdm_port_parent_path;
g_assert (MM_IS_PORT_QMI (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_QMI (l->data);
found = MM_PORT_QMI (l->data);
}
g_set_error (error,
MM_CORE_ERROR,
MM_CORE_ERROR_NOT_FOUND,
"Couldn't find associated QMI port for 'net/%s'",
mm_port_get_device (data));
return NULL;
g_list_free_full (cdc_wdm_qmi_ports, g_object_unref);
if (!found)
g_set_error (error,
MM_CORE_ERROR,
MM_CORE_ERROR_NOT_FOUND,
"Couldn't find associated QMI port for 'net/%s'",
mm_port_get_device (data));
return found;
}
#endif /* WITH_QMI */
@@ -637,6 +642,7 @@ mm_base_modem_peek_port_mbim_for_data (MMBaseModem *self,
{
GList *cdc_wdm_mbim_ports, *l;
const gchar *net_port_parent_path;
MMPortMbim *found = NULL;
g_warn_if_fail (mm_port_get_subsys (data) == MM_PORT_SUBSYS_NET);
net_port_parent_path = mm_kernel_device_get_parent_sysfs_path (mm_port_peek_kernel_device (data));
@@ -654,21 +660,26 @@ mm_base_modem_peek_port_mbim_for_data (MMBaseModem *self,
MM_PORT_SUBSYS_USB,
MM_PORT_TYPE_MBIM,
NULL);
for (l = cdc_wdm_mbim_ports; l; l = g_list_next (l)) {
for (l = cdc_wdm_mbim_ports; l && !found; l = g_list_next (l)) {
const gchar *wdm_port_parent_path;
g_assert (MM_IS_PORT_MBIM (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_MBIM (l->data);
found = MM_PORT_MBIM (l->data);
}
g_set_error (error,
MM_CORE_ERROR,
MM_CORE_ERROR_NOT_FOUND,
"Couldn't find associated MBIM port for 'net/%s'",
mm_port_get_device (data));
return NULL;
g_list_free_full (cdc_wdm_mbim_ports, g_object_unref);
if (!found)
g_set_error (error,
MM_CORE_ERROR,
MM_CORE_ERROR_NOT_FOUND,
"Couldn't find associated MBIM port for 'net/%s'",
mm_port_get_device (data));
return found;
}
#endif /* WITH_MBIM */