libgweather/backport-memory-fixes.patch
Florian Müllner b3cd3842b9 Backport memory fixes
Fix some dodgy memory handling that result in session crashes.
2017-04-27 13:41:24 +02:00

87 lines
3.0 KiB
Diff

From 8cd4af9f34259de52bf25ecad27feb61927a0207 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Florian=20M=C3=BCllner?= <fmuellner@gnome.org>
Date: Sun, 19 Mar 2017 17:25:11 +0100
Subject: [PATCH 1/2] weather: Guard against segfault
When GWeatherInfo:location is set to %NULL, the default location will
be used. Currently the code assumes that this fallback can always be
resolved, however find_by_station_code() may return %NULL, resulting
in a segfault.
https://bugzilla.gnome.org/show_bug.cgi?id=780278
---
libgweather/gweather-weather.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/libgweather/gweather-weather.c b/libgweather/gweather-weather.c
index 87fb8fd..20b8c58 100644
--- a/libgweather/gweather-weather.c
+++ b/libgweather/gweather-weather.c
@@ -2002,7 +2002,6 @@ gweather_info_set_location_internal (GWeatherInfo *info,
if (priv->glocation)
gweather_location_unref (priv->glocation);
- _weather_location_free (&priv->location);
priv->glocation = location;
@@ -2023,8 +2022,12 @@ gweather_info_set_location_internal (GWeatherInfo *info,
priv->glocation = gweather_location_find_by_station_code (world, station_code);
}
- _gweather_location_update_weather_location (priv->glocation,
- &priv->location);
+ if (priv->glocation) {
+ _weather_location_free (&priv->location);
+ _gweather_location_update_weather_location (priv->glocation,
+ &priv->location);
+ }
+
if (name) {
g_free (priv->location.name);
priv->location.name = g_strdup (name);
--
2.12.2
From d40143d7091a0c0445d6687d79084f4b2c81e863 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Florian=20M=C3=BCllner?= <fmuellner@gnome.org>
Date: Sat, 22 Apr 2017 04:30:37 +0200
Subject: [PATCH 2/2] location: Don't release libxml-allocated memory with
g_free()
Don't assume that xmlFree() and g_free() are interchangeable, copy
the value returned from XML like we already do for other struct
members.
https://bugzilla.gnome.org/show_bug.cgi?id=781828
---
libgweather/gweather-location.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/libgweather/gweather-location.c b/libgweather/gweather-location.c
index ccbb8ee..31e236f 100644
--- a/libgweather/gweather-location.c
+++ b/libgweather/gweather-location.c
@@ -165,7 +165,8 @@ location_new_from_xml (GWeatherParser *parser, GWeatherLocationLevel level,
if (!value)
goto error_out;
- loc->english_name = value;
+ loc->english_name = g_strdup (value);
+
if (loc->msgctxt) {
loc->local_name = g_strdup (g_dpgettext2 ("libgweather-locations",
(char*) loc->msgctxt, value));
@@ -180,6 +181,7 @@ location_new_from_xml (GWeatherParser *parser, GWeatherLocationLevel level,
normalized = g_utf8_normalize (loc->english_name, -1, G_NORMALIZE_ALL);
loc->english_sort_name = g_utf8_casefold (normalized, -1);
g_free (normalized);
+ xmlFree (value);
} else if (!strcmp (tagname, "iso-code") && !loc->country_code) {
value = _gweather_parser_get_value (parser);
if (!value)
--
2.12.2