[PATCH] device: add null check on `self->priv->modem' in clear_modem

Ben Chan benchan at chromium.org
Fri Mar 3 18:29:50 UTC 2017


clear_modem() can be invoked from set_property() and dispose(), where
`self->priv->modem' may be NULL. This patch adds a null check on the
modem object to make sure we don't run g_object_run_dispose() on a null
modem object.
---
 src/mm-device.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/mm-device.c b/src/mm-device.c
index 803e64d3..6c856289 100644
--- a/src/mm-device.c
+++ b/src/mm-device.c
@@ -302,10 +302,12 @@ clear_modem (MMDevice *self)
         self->priv->modem_valid_id = 0;
     }
 
-    /* Run dispose before unref-ing, in order to cleanup the SIM object,
-     * if any (which also holds a reference to the modem object) */
-    g_object_run_dispose (G_OBJECT (self->priv->modem));
-    g_clear_object (&(self->priv->modem));
+    if (self->priv->modem) {
+        /* Run dispose before unref-ing, in order to cleanup the SIM object,
+         * if any (which also holds a reference to the modem object) */
+        g_object_run_dispose (G_OBJECT (self->priv->modem));
+        g_clear_object (&(self->priv->modem));
+    }
 }
 
 void
-- 
2.12.0.rc1.440.g5b76565f74-goog



More information about the ModemManager-devel mailing list