aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2021-03-18 11:20:02 +0100
committerAleksander Morgado <aleksander@aleksander.es>2021-03-18 14:27:34 +0100
commitab007a449638eeacaf6f626b707842af5274db95 (patch)
tree3816571b0c625f45f9feef67d1479fe371f0ffca
parentbf3065cdaa49b8cea9d91caaeb75136d547ddf4c (diff)
base-modem: plug leaks when organizing ports
The GLists maintained in the logic need to be explicitly freed (just the lists, not the list contents) if we exit early on error or if we end up deciding that the specific ports are available but unsupported by the plugin (e.g. if a plugin that doesn't support net ports finds net ports in the modem). ==225333== 24 bytes in 1 blocks are definitely lost in loss record 2,024 of 5,525 ==225333== at 0x483E77F: malloc (vg_replace_malloc.c:307) ==225333== by 0x506C539: g_malloc (in /usr/lib/libglib-2.0.so.0.6600.7) ==225333== by 0x508DC8F: g_slice_alloc (in /usr/lib/libglib-2.0.so.0.6600.7) ==225333== by 0x50636B4: g_list_append (in /usr/lib/libglib-2.0.so.0.6600.7) ==225333== by 0x17E671: mm_base_modem_organize_ports (mm-base-modem.c:1298) ==225333== by 0x1E4409: mm_plugin_create_modem (mm-plugin.c:1094) ==225333== by 0x162C81: mm_device_create_modem (mm-device.c:481) ==225333== by 0x15DE60: device_support_check_ready (mm-base-manager.c:218) ==225333== by 0x4EA8173: ??? (in /usr/lib/libgio-2.0.so.0.6600.7) ==225333== by 0x4EAC6E8: ??? (in /usr/lib/libgio-2.0.so.0.6600.7) ==225333== by 0x16730F: device_context_run_ready (mm-plugin-manager.c:1533) ==225333== by 0x4EA8173: ??? (in /usr/lib/libgio-2.0.so.0.6600.7)
-rw-r--r--src/mm-base-modem.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/mm-base-modem.c b/src/mm-base-modem.c
index bb2e51dd..ad34ab1d 100644
--- a/src/mm-base-modem.c
+++ b/src/mm-base-modem.c
@@ -1177,15 +1177,17 @@ mm_base_modem_organize_ports (MMBaseModem *self,
MMPortSerialGps *gps = NULL;
MMPortSerial *audio = NULL;
MMPortSerialAt *data_at_primary = NULL;
- GList *data_at = NULL;
- GList *data_net = NULL;
+ GList *l;
+ /* These lists don't keep full references, so they should be
+ * g_list_free()-ed on error exits */
+ g_autoptr(GList) data_at = NULL;
+ g_autoptr(GList) data_net = NULL;
#if defined WITH_QMI
- GList *qmi = NULL;
+ g_autoptr(GList) qmi = NULL;
#endif
#if defined WITH_MBIM
- GList *mbim = NULL;
+ g_autoptr(GList) mbim = NULL;
#endif
- GList *l;
g_return_val_if_fail (MM_IS_BASE_MODEM (self), FALSE);
@@ -1411,7 +1413,7 @@ mm_base_modem_organize_ports (MMBaseModem *self,
if (data_net) {
if (self->priv->data_net_supported) {
g_list_foreach (data_net, (GFunc)g_object_ref, NULL);
- self->priv->data = g_list_concat (self->priv->data, data_net);
+ self->priv->data = g_list_concat (self->priv->data, g_steal_pointer (&data_net));
} else
mm_obj_dbg (self, "net ports available but ignored");
}
@@ -1424,7 +1426,7 @@ mm_base_modem_organize_ports (MMBaseModem *self,
self->priv->data = g_list_append (self->priv->data, g_object_ref (data_at_primary));
if (data_at) {
g_list_foreach (data_at, (GFunc)g_object_ref, NULL);
- self->priv->data = g_list_concat (self->priv->data, data_at);
+ self->priv->data = g_list_concat (self->priv->data, g_steal_pointer (&data_at));
}
} else
mm_obj_dbg (self, "at data ports available but ignored");
@@ -1451,14 +1453,14 @@ mm_base_modem_organize_ports (MMBaseModem *self,
mm_port_peek_kernel_device (
MM_PORT (self->priv->data->data))));
g_list_foreach (qmi, (GFunc)g_object_ref, NULL);
- self->priv->qmi = qmi;
+ self->priv->qmi = g_steal_pointer (&qmi);
}
#endif
#if defined WITH_MBIM
if (mbim) {
g_list_foreach (mbim, (GFunc)g_object_ref, NULL);
- self->priv->mbim = mbim;
+ self->priv->mbim = g_steal_pointer (&mbim);
}
#endif