From 024bb97a128f70eab8cc85a1e24540209953cea5 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Wed, 16 Aug 2017 18:07:19 -0300 Subject: [PATCH] color: Avoid casting before checking for errors When the asynchronous operation is finished in the Color panel, the user may potentially have already changed to another panel, making the CcColorPanel reference invalid. In the callback, the first thing that is done is casting (and type-checking) the CcColorPanel pointer, causing a segmentation fault. Fix that by only casting anything after checking the result of the asynchronous call. https://bugzilla.gnome.org/show_bug.cgi?id=786096 --- panels/color/cc-color-panel.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/panels/color/cc-color-panel.c b/panels/color/cc-color-panel.c index 32f122892..2bbe41a50 100644 --- a/panels/color/cc-color-panel.c +++ b/panels/color/cc-color-panel.c @@ -2019,21 +2019,29 @@ gcm_prefs_connect_cb (GObject *object, GAsyncResult *res, gpointer user_data) { + CcColorPanelPrivate *priv; + CcColorPanel *prefs; gboolean ret; GError *error = NULL; - CcColorPanel *prefs = CC_COLOR_PANEL (user_data); - CcColorPanelPrivate *priv = prefs->priv; - ret = cd_client_connect_finish (priv->client, + ret = cd_client_connect_finish (CD_CLIENT (object), res, &error); if (!ret) { - g_warning ("failed to connect to colord: %s", error->message); + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + g_warning ("failed to connect to colord: %s", error->message); + g_error_free (error); return; } + /* Only cast the parameters after making sure it didn't fail. At this point, + * the user can potentially already have changed to another panel, effectively + * making user_data invalid. */ + prefs = CC_COLOR_PANEL (user_data); + priv = prefs->priv; + /* set calibrate button sensitivity */ gcm_prefs_sensor_coldplug (prefs);