From c16bcdf68c0d1e2d027a5a44b7e3b4bf29d4aee3 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 11 Oct 2012 11:41:15 +0200 Subject: core: make sure objects retrieved with g_object_get() are valid in the ifaces The interfaces usually retrieve objects (e.g. skeletons) from the Modem object using g_object_get(), but we didn't make sure that these objects were actually valid before using them. This should clean up errors happening when the modem gets unplugged and still some actions are ongoing. Should fix https://bugzilla.gnome.org/show_bug.cgi?id=685933 --- src/mm-iface-modem-location.c | 169 +++++++++++++++++++----------------------- 1 file changed, 75 insertions(+), 94 deletions(-) (limited to 'src/mm-iface-modem-location.c') diff --git a/src/mm-iface-modem-location.c b/src/mm-iface-modem-location.c index d6e897c2..6009fd12 100644 --- a/src/mm-iface-modem-location.c +++ b/src/mm-iface-modem-location.c @@ -379,7 +379,8 @@ update_location_source_status (MMIfaceModemLocation *self, g_object_get (self, MM_IFACE_MODEM_LOCATION_DBUS_SKELETON, &skeleton, NULL); - g_assert (skeleton != NULL); + if (!skeleton) + return; /* Update status in the interface */ mask = mm_gdbus_modem_location_get_enabled (skeleton); @@ -440,7 +441,8 @@ setup_gathering_context_complete_and_free (SetupGatheringContext *ctx) { g_simple_async_result_complete_in_idle (ctx->result); g_object_unref (ctx->result); - g_object_unref (ctx->skeleton); + if (ctx->skeleton) + g_object_unref (ctx->skeleton); g_object_unref (ctx->self); g_free (ctx); } @@ -598,7 +600,14 @@ setup_gathering (MMIfaceModemLocation *self, g_object_get (self, MM_IFACE_MODEM_LOCATION_DBUS_SKELETON, &ctx->skeleton, NULL); - g_assert (ctx->skeleton != NULL); + if (!ctx->skeleton) { + g_simple_async_result_set_error (ctx->result, + MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Couldn't get interface skeleton"); + setup_gathering_context_complete_and_free (ctx); + return; + } /* Get current list of enabled sources */ currently_enabled = mm_gdbus_modem_location_get_enabled (ctx->skeleton); @@ -880,35 +889,14 @@ struct _DisablingContext { MmGdbusModemLocation *skeleton; }; -static DisablingContext * -disabling_context_new (MMIfaceModemLocation *self, - GAsyncReadyCallback callback, - gpointer user_data) -{ - DisablingContext *ctx; - - ctx = g_new0 (DisablingContext, 1); - ctx->self = g_object_ref (self); - ctx->result = g_simple_async_result_new (G_OBJECT (self), - callback, - user_data, - disabling_context_new); - ctx->step = DISABLING_STEP_FIRST; - g_object_get (ctx->self, - MM_IFACE_MODEM_LOCATION_DBUS_SKELETON, &ctx->skeleton, - NULL); - g_assert (ctx->skeleton != NULL); - - return ctx; -} - static void disabling_context_complete_and_free (DisablingContext *ctx) { g_simple_async_result_complete_in_idle (ctx->result); g_object_unref (ctx->self); g_object_unref (ctx->result); - g_object_unref (ctx->skeleton); + if (ctx->skeleton) + g_object_unref (ctx->skeleton); g_free (ctx); } @@ -969,9 +957,28 @@ mm_iface_modem_location_disable (MMIfaceModemLocation *self, GAsyncReadyCallback callback, gpointer user_data) { - interface_disabling_step (disabling_context_new (self, - callback, - user_data)); + DisablingContext *ctx; + + ctx = g_new0 (DisablingContext, 1); + ctx->self = g_object_ref (self); + ctx->result = g_simple_async_result_new (G_OBJECT (self), + callback, + user_data, + mm_iface_modem_location_disable); + ctx->step = DISABLING_STEP_FIRST; + g_object_get (ctx->self, + MM_IFACE_MODEM_LOCATION_DBUS_SKELETON, &ctx->skeleton, + NULL); + if (!ctx->skeleton) { + g_simple_async_result_set_error (ctx->result, + MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Couldn't get interface skeleton"); + disabling_context_complete_and_free (ctx); + return; + } + + interface_disabling_step (ctx); } /*****************************************************************************/ @@ -993,30 +1000,6 @@ struct _EnablingContext { MmGdbusModemLocation *skeleton; }; -static EnablingContext * -enabling_context_new (MMIfaceModemLocation *self, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - EnablingContext *ctx; - - ctx = g_new0 (EnablingContext, 1); - ctx->self = g_object_ref (self); - ctx->cancellable = g_object_ref (cancellable); - ctx->result = g_simple_async_result_new (G_OBJECT (self), - callback, - user_data, - enabling_context_new); - ctx->step = ENABLING_STEP_FIRST; - g_object_get (ctx->self, - MM_IFACE_MODEM_LOCATION_DBUS_SKELETON, &ctx->skeleton, - NULL); - g_assert (ctx->skeleton != NULL); - - return ctx; -} - static void enabling_context_complete_and_free (EnablingContext *ctx) { @@ -1024,7 +1007,8 @@ enabling_context_complete_and_free (EnablingContext *ctx) g_object_unref (ctx->self); g_object_unref (ctx->result); g_object_unref (ctx->cancellable); - g_object_unref (ctx->skeleton); + if (ctx->skeleton) + g_object_unref (ctx->skeleton); g_free (ctx); } @@ -1111,10 +1095,29 @@ mm_iface_modem_location_enable (MMIfaceModemLocation *self, GAsyncReadyCallback callback, gpointer user_data) { - interface_enabling_step (enabling_context_new (self, - cancellable, - callback, - user_data)); + EnablingContext *ctx; + + ctx = g_new0 (EnablingContext, 1); + ctx->self = g_object_ref (self); + ctx->cancellable = g_object_ref (cancellable); + ctx->result = g_simple_async_result_new (G_OBJECT (self), + callback, + user_data, + mm_iface_modem_location_enable); + ctx->step = ENABLING_STEP_FIRST; + g_object_get (ctx->self, + MM_IFACE_MODEM_LOCATION_DBUS_SKELETON, &ctx->skeleton, + NULL); + if (!ctx->skeleton) { + g_simple_async_result_set_error (ctx->result, + MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Couldn't get interface skeleton"); + enabling_context_complete_and_free (ctx); + return; + } + + interface_enabling_step (ctx); } /*****************************************************************************/ @@ -1138,30 +1141,6 @@ struct _InitializationContext { MMModemLocationSource capabilities; }; -static InitializationContext * -initialization_context_new (MMIfaceModemLocation *self, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - InitializationContext *ctx; - - ctx = g_new0 (InitializationContext, 1); - ctx->self = g_object_ref (self); - ctx->capabilities = MM_MODEM_LOCATION_SOURCE_NONE; - ctx->cancellable = g_object_ref (cancellable); - ctx->result = g_simple_async_result_new (G_OBJECT (self), - callback, - user_data, - initialization_context_new); - ctx->step = INITIALIZATION_STEP_FIRST; - g_object_get (ctx->self, - MM_IFACE_MODEM_LOCATION_DBUS_SKELETON, &ctx->skeleton, - NULL); - g_assert (ctx->skeleton != NULL); - return ctx; -} - static void initialization_context_complete_and_free (InitializationContext *ctx) { @@ -1279,9 +1258,6 @@ mm_iface_modem_location_initialize_finish (MMIfaceModemLocation *self, GAsyncResult *res, GError **error) { - g_return_val_if_fail (MM_IS_IFACE_MODEM_LOCATION (self), FALSE); - g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE); - return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error); } @@ -1291,10 +1267,9 @@ mm_iface_modem_location_initialize (MMIfaceModemLocation *self, GAsyncReadyCallback callback, gpointer user_data) { + InitializationContext *ctx; MmGdbusModemLocation *skeleton = NULL; - g_return_if_fail (MM_IS_IFACE_MODEM_LOCATION (self)); - /* Did we already create it? */ g_object_get (self, MM_IFACE_MODEM_LOCATION_DBUS_SKELETON, &skeleton, @@ -1315,18 +1290,24 @@ mm_iface_modem_location_initialize (MMIfaceModemLocation *self, } /* Perform async initialization here */ - interface_initialization_step (initialization_context_new (self, - cancellable, - callback, - user_data)); - g_object_unref (skeleton); + + ctx = g_new0 (InitializationContext, 1); + ctx->self = g_object_ref (self); + ctx->capabilities = MM_MODEM_LOCATION_SOURCE_NONE; + ctx->cancellable = g_object_ref (cancellable); + ctx->result = g_simple_async_result_new (G_OBJECT (self), + callback, + user_data, + mm_iface_modem_location_initialize); + ctx->step = INITIALIZATION_STEP_FIRST; + ctx->skeleton = skeleton; + + interface_initialization_step (ctx); } void mm_iface_modem_location_shutdown (MMIfaceModemLocation *self) { - g_return_if_fail (MM_IS_IFACE_MODEM_LOCATION (self)); - /* Unexport DBus interface and remove the skeleton */ mm_gdbus_object_skeleton_set_modem_location (MM_GDBUS_OBJECT_SKELETON (self), NULL); g_object_set (self, -- cgit v1.2.3-70-g09d2