[Xfce4-commits] <xfce4-weather-plugin:master> Fix crashes related to updates and timer handling.

Harald Judt noreply at xfce.org
Sun Dec 9 23:44:29 CET 2012


Updating branch refs/heads/master
         to 1eda67307db7d676cb77724805abdfed42dc444b (commit)
       from 2081c67d3c8fe5290b4ef2365cb573f00d69223d (commit)

commit 1eda67307db7d676cb77724805abdfed42dc444b
Author: Harald Judt <h.judt at gmx.at>
Date:   Sun Dec 9 19:24:54 2012 +0100

    Fix crashes related to updates and timer handling.
    
    Closing the dialog will clear its data, so the update routine will only get
    a NULL pointer and cause a crash. Reading data from the cache file is not
    the task of the config dialog, but of the update_with_reset function, so
    it belongs there and read_cache_file can be static. Also it shouldn't happen
    after we have downloaded the new data but before it, so the new data won't
    get overwritten by the old data. Finally, set timer ids to 0 so the checks
    for them are actually useful.

 panel-plugin/weather-config.c |   17 ++++++++---------
 panel-plugin/weather.c        |   22 +++++++++++++++++++---
 panel-plugin/weather.h        |    2 --
 3 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/panel-plugin/weather-config.c b/panel-plugin/weather-config.c
index 5877a2c..924f28d 100644
--- a/panel-plugin/weather-config.c
+++ b/panel-plugin/weather-config.c
@@ -143,16 +143,11 @@ static gboolean
 schedule_data_update(gpointer user_data)
 {
     xfceweather_dialog *dialog = (xfceweather_dialog *) user_data;
-
-    if (dialog == NULL)
-        return FALSE;
+    plugin_data *pd = dialog->pd;
 
     /* force update of downloaded data */
     weather_debug("Delayed update timer expired, now scheduling data update.");
-    update_weatherdata_with_reset(dialog->pd, TRUE);
-
-    /* make use of previously saved data */
-    read_cache_file(dialog->pd);
+    update_weatherdata_with_reset(pd, TRUE);
 
     gtk_spinner_stop(GTK_SPINNER(dialog->update_spinner));
     gtk_widget_hide(GTK_WIDGET(dialog->update_spinner));
@@ -165,12 +160,16 @@ schedule_delayed_data_update(xfceweather_dialog *dialog)
 {
     weather_debug("Starting delayed data update.");
     /* cancel any update that was scheduled before */
-    if (dialog->timer_id)
+    if (dialog->timer_id) {
         g_source_remove(dialog->timer_id);
+        dialog->timer_id = 0;
+    }
 
     /* stop any updates that could be performed by weather.c */
-    if (dialog->pd->updatetimeout)
+    if (dialog->pd->updatetimeout) {
         g_source_remove(dialog->pd->updatetimeout);
+        dialog->pd->updatetimeout = 0;
+    }
 
     gtk_widget_show(GTK_WIDGET(dialog->update_spinner));
     gtk_spinner_start(GTK_SPINNER(dialog->update_spinner));
diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
index 5bd9217..454c836 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -824,12 +824,12 @@ write_cache_file(plugin_data *data)
 }
 
 
-void
+static void
 read_cache_file(plugin_data *data)
 {
     GKeyFile *keyfile;
     GError **err;
-    xml_weather *wd = data->weatherdata;
+    xml_weather *wd;
     xml_time *timeslice = NULL;
     xml_location *loc = NULL;
     time_t now_t = time(NULL), cache_date_t;
@@ -837,6 +837,11 @@ read_cache_file(plugin_data *data)
     gchar *timestring;
     gint msl, timezone, num_timeslices, i, j;
 
+    g_assert(data != NULL);
+    if (G_UNLIKELY(data == NULL))
+        return;
+    wd = data->weatherdata;
+
     if (G_UNLIKELY(data->lat == NULL || data->lon == NULL))
         return;
 
@@ -963,8 +968,15 @@ read_cache_file(plugin_data *data)
 void
 update_weatherdata_with_reset(plugin_data *data, gboolean clear)
 {
-    if (data->updatetimeout)
+    weather_debug("Update weatherdata with reset.");
+    g_assert(data != NULL);
+    if (G_UNLIKELY(data == NULL))
+        return;
+
+    if (data->updatetimeout) {
         g_source_remove(data->updatetimeout);
+        data->updatetimeout = 0;
+    }
 
     memset(&data->last_data_update, 0, sizeof(data->last_data_update));
     memset(&data->last_astro_update, 0, sizeof(data->last_astro_update));
@@ -975,6 +987,9 @@ update_weatherdata_with_reset(plugin_data *data, gboolean clear)
     if (clear && data->weatherdata) {
         xml_weather_free(data->weatherdata);
         data->weatherdata = g_slice_new0(xml_weather);
+
+        /* make use of previously saved data */
+        read_cache_file(data);
     }
 
     update_weatherdata(data);
@@ -983,6 +998,7 @@ update_weatherdata_with_reset(plugin_data *data, gboolean clear)
         g_timeout_add_seconds(UPDATE_INTERVAL,
                               (GSourceFunc) update_weatherdata,
                               data);
+    weather_debug("Updated weatherdata with reset.");
 }
 
 
diff --git a/panel-plugin/weather.h b/panel-plugin/weather.h
index a27c18a..3a1d8a2 100644
--- a/panel-plugin/weather.h
+++ b/panel-plugin/weather.h
@@ -114,8 +114,6 @@ void forecast_click(GtkWidget *widget,
 
 gchar *get_cache_directory(void);
 
-void read_cache_file(plugin_data *data);
-
 void update_icon(plugin_data *data);
 
 void update_scrollbox(plugin_data *data);


More information about the Xfce4-commits mailing list