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:
parent
f69c1e106b
commit
024bb97a12
1 changed files with 12 additions and 4 deletions
|
@ -2019,21 +2019,29 @@ gcm_prefs_connect_cb (GObject *object,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
|
CcColorPanelPrivate *priv;
|
||||||
|
CcColorPanel *prefs;
|
||||||
gboolean ret;
|
gboolean ret;
|
||||||
GError *error = NULL;
|
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,
|
res,
|
||||||
&error);
|
&error);
|
||||||
if (!ret)
|
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);
|
g_error_free (error);
|
||||||
return;
|
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 */
|
/* set calibrate button sensitivity */
|
||||||
gcm_prefs_sensor_coldplug (prefs);
|
gcm_prefs_sensor_coldplug (prefs);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue