From e163ab504a32fc68ed95b9b818ce648e1b3b50ab Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 9 May 2022 22:44:56 +0200 Subject: [PATCH] broadband-modem-mbim: fix task completion when peeking device fails We cannot call peek_device() when we have already created a GTask for the async operation, because if the operation failed we would be completing the async operation with a totally different GTask than the one we had created ourselves, triggering memory leaks and leaving modem references around that should not exist (as the GTask we create holds a modem reference). Issue found in the context of debugging this, may actually be fully related: https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/550 --- src/mm-broadband-modem-mbim.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index c987c6d5..1ca8789b 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -194,6 +194,25 @@ peek_device (gpointer self, return TRUE; } +static gboolean +peek_device_in_task (gpointer self, + MbimDevice **o_device, + GTask *task) + +{ + MMPortMbim *port; + + port = mm_broadband_modem_mbim_peek_port_mbim (MM_BROADBAND_MODEM_MBIM (self)); + if (!port) { + g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Couldn't peek MBIM port"); + g_object_unref (task); + return FALSE; + } + + *o_device = mm_port_mbim_peek_device (port); + return TRUE; +} + #if defined WITH_QMI && QMI_MBIM_QMUX_SUPPORTED static QmiClient * @@ -8603,7 +8622,7 @@ load_sim_slots_mbim (GTask *task) self = g_task_get_source_object (task); - if (!peek_device (self, &device, NULL, NULL)) + if (!peek_device_in_task (self, &device, task)) return; message = mbim_message_ms_basic_connect_extensions_sys_caps_query_new (NULL); @@ -8792,7 +8811,7 @@ set_primary_sim_slot_mbim (GTask *task) self = g_task_get_source_object (task); - if (!peek_device (self, &device, NULL, NULL)) + if (!peek_device_in_task (self, &device, task)) return; message = mbim_message_ms_basic_connect_extensions_device_slot_mappings_query_new (NULL);