[Xfce4-commits] <xfce4-weather-plugin:master> Set data to NULL after free, but report double-free.
Harald Judt
noreply at xfce.org
Wed Jul 25 08:10:01 CEST 2012
Updating branch refs/heads/master
to a7eafaaac94476c0a6143ded7883b5bf5b82d9f3 (commit)
from 576f9d15c39e913724a8cf17dd3763e3e4d17cae (commit)
commit a7eafaaac94476c0a6143ded7883b5bf5b82d9f3
Author: Harald Judt <h.judt at gmx.at>
Date: Wed Jul 25 08:00:54 2012 +0200
Set data to NULL after free, but report double-free.
To prevent undefined behaviour, set structs to NULL after
freeing them, but also put assertions in to report double-free
attempts.
panel-plugin/weather-parsers.c | 12 ++++++++++++
panel-plugin/weather.c | 2 ++
2 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/panel-plugin/weather-parsers.c b/panel-plugin/weather-parsers.c
index c0326fb..6442d42 100644
--- a/panel-plugin/weather-parsers.c
+++ b/panel-plugin/weather-parsers.c
@@ -239,6 +239,9 @@ void parse_location (xmlNode * cur_node, xml_location *loc)
static void xml_location_free(xml_location *loc)
{
+ g_assert(loc != NULL);
+ if (G_UNLIKELY(loc == NULL))
+ return;
g_free(loc->altitude);
g_free(loc->latitude);
g_free(loc->longitude);
@@ -261,21 +264,30 @@ static void xml_location_free(xml_location *loc)
g_free(loc->precipitation_unit);
g_free(loc->symbol);
g_slice_free (xml_location, loc);
+ loc = NULL;
}
void xml_time_free(xml_time *timeslice)
{
+ g_assert(timeslice != NULL);
+ if (G_UNLIKELY(timeslice == NULL))
+ return;
xml_location_free(timeslice->location);
g_slice_free (xml_time, timeslice);
+ timeslice = NULL;
}
void xml_weather_free (xml_weather *data)
{
guint i;
+ g_assert(data != NULL);
+ if (G_UNLIKELY(data == NULL))
+ return;
for (i = 0; i < data->num_timeslices; i++) {
xml_time_free(data->timeslice[i]);
}
xml_time_free(data->current_conditions);
g_slice_free (xml_weather, data);
+ data = NULL;
}
diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
index c95cccb..5eb81f3 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -1005,6 +1005,7 @@ static void
xfceweather_free (XfcePanelPlugin *plugin,
xfceweather_data *data)
{
+ g_assert(data != NULL);
weather_http_cleanup_qeue ();
if (data->weatherdata)
@@ -1035,6 +1036,7 @@ xfceweather_free (XfcePanelPlugin *plugin,
g_array_free (data->labels, TRUE);
g_slice_free (xfceweather_data, data);
+ data = NULL;
}
More information about the Xfce4-commits
mailing list