From 0b63dbdef7f738b2ca22d87c6b72f024281cba33 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 10 May 2016 17:52:13 +0200 Subject: [PATCH] wwan: return from send_pin_ready() when operation cancelled and fix leak We call the asynchrnous function mm_sim_send_pin() without taking a reference on @self. During send_pin_ready() we must first check whether the request was cancelled because self might be a dangling pointer at this point. Also, avoid leaking @error if the ctx is no longer valid. Fixes: aa0b379699fe8cb4ec9ef28fc493c0e499c892d8 (cherry picked from commit 37827fcafa7ccf2da3756ddc57298db92990c2ba) --- src/devices/wwan/nm-modem-broadband.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/devices/wwan/nm-modem-broadband.c b/src/devices/wwan/nm-modem-broadband.c index 5736df3c8a..1a6e6b2524 100644 --- a/src/devices/wwan/nm-modem-broadband.c +++ b/src/devices/wwan/nm-modem-broadband.c @@ -381,10 +381,13 @@ connect_ready (MMModemSimple *simple_iface, static void send_pin_ready (MMSim *sim, GAsyncResult *result, NMModemBroadband *self) { - GError *error = NULL; + gs_free_error GError *error = NULL; mm_sim_send_pin_finish (sim, result, &error); + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + return; + if (!self->priv->ctx || self->priv->ctx->step != CONNECT_STEP_UNLOCK) return; @@ -396,7 +399,6 @@ send_pin_ready (MMSim *sim, GAsyncResult *result, NMModemBroadband *self) } else { g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, FALSE, translate_mm_error (error)); } - g_error_free (error); return; }