summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2017-10-07 14:06:06 +0200
committerAleksander Morgado <aleksander@aleksander.es>2017-10-07 14:21:57 +0200
commite8ce6a04e9fc8b15fc6e28433c3b051370acb206 (patch)
tree454ce04269a1aa9da8bcd64d6060bd5a72a6702a
parentf613103fc3ff0426049054fe8e204e17cac7bcba (diff)
downloadModemManager-e8ce6a04e9fc8b15fc6e28433c3b051370acb206.tar.gz
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) (cherry picked from commit 58e6f652a10e57eeea1a8ccb0c440c3171a9ba33)
-rw-r--r--src/mm-base-modem.c43
1 files changed, 27 insertions, 16 deletions
diff --git a/src/mm-base-modem.c b/src/mm-base-modem.c
index 9cd7c5fab..243ccb954 100644
--- a/src/mm-base-modem.c
+++ b/src/mm-base-modem.c
@@ -534,6 +534,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_port_get_parent_path (data);
@@ -551,21 +552,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_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_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 */
@@ -608,6 +613,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_port_get_parent_path (data);
@@ -625,21 +631,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_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_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 */