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
This commit is contained in:
Georges Basile Stavracas Neto 2017-08-16 18:07:19 -03:00
parent f69c1e106b
commit 024bb97a12

View file

@ -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);