[gnome-control-center] color: Avoid casting before checking for errors
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] color: Avoid casting before checking for errors
- Date: Wed, 16 Aug 2017 21:13:07 +0000 (UTC)
commit 024bb97a128f70eab8cc85a1e24540209953cea5
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Wed Aug 16 18:07:19 2017 -0300
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 files changed, 12 insertions(+), 4 deletions(-)
---
diff --git a/panels/color/cc-color-panel.c b/panels/color/cc-color-panel.c
index 32f1228..2bbe41a 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]