diff options
author | Carlos Garnacho <carlosg@gnome.org> | 2018-04-13 18:42:41 +0200 |
---|---|---|
committer | Carlos Garnacho <carlosg@gnome.org> | 2020-11-13 18:38:04 +0100 |
commit | 32cb857b608258e5368272c50d83d5e5bda63daf (patch) | |
tree | cd1e8129b8cb496a20f814e4021b864b7c46446c | |
parent | 7ed0a4da5f69390413c22f1b9a3bbfa29ad6d68e (diff) | |
download | libgweather-32cb857b608258e5368272c50d83d5e5bda63daf.tar.gz |
owm: Plug xmlGetProp leakswip/carlosg/plug-leaks
The OWM parser has some xmlGetProp() string leaks. Free the
resulting string in all missed cases.
https://bugzilla.gnome.org/show_bug.cgi?id=795236
-rw-r--r-- | libgweather/weather-owm.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/libgweather/weather-owm.c b/libgweather/weather-owm.c index e91eb3b..b8447f8 100644 --- a/libgweather/weather-owm.c +++ b/libgweather/weather-owm.c @@ -180,6 +180,7 @@ read_symbol (GWeatherInfo *info, val = xmlGetProp (node, XC("number")); ref.symbol = strtol ((char*) val, NULL, 0) - 1; + xmlFree (val); obj = bsearch (&ref, symbols, G_N_ELEMENTS (symbols), sizeof (struct owm_symbol), symbol_compare); @@ -208,9 +209,11 @@ read_wind_direction (GWeatherInfo *info, for (i = 0; i < G_N_ELEMENTS (wind_directions); i++) { if (strcmp ((char*) val, wind_directions[i].name) == 0) { info->priv->wind = wind_directions[i].direction; + xmlFree (val); return; } } + xmlFree (val); } static inline void @@ -226,6 +229,7 @@ read_wind_speed (GWeatherInfo *info, mps = g_ascii_strtod ((char*) val, NULL); info->priv->windspeed = WINDSPEED_MS_TO_KNOTS (mps); + xmlFree (val); } static inline void @@ -237,15 +241,19 @@ read_temperature (GWeatherInfo *info, double celsius; unit = xmlGetProp (node, XC("unit")); - if (unit == NULL || strcmp ((char*)unit, "celsius")) + if (unit == NULL || strcmp ((char*)unit, "celsius")) { + xmlFree (unit); return; + } + xmlFree (unit); val = xmlGetProp (node, XC("value")); if (val == NULL) return; celsius = g_ascii_strtod ((char*) val, NULL); info->priv->temp = TEMP_C_TO_F (celsius); + xmlFree (val); } static inline void @@ -258,15 +266,19 @@ read_pressure (GWeatherInfo *info, /* hPa == mbar */ unit = xmlGetProp (node, XC("unit")); - if (unit == NULL || strcmp ((char*)unit, "hPa")) + if (unit == NULL || strcmp ((char*)unit, "hPa")) { + xmlFree (unit); return; + } + xmlFree (unit); val = xmlGetProp (node, XC("value")); if (val == NULL) return; hpa = g_ascii_strtod ((char*) val, NULL); info->priv->pressure = PRESSURE_MBAR_TO_INCH (hpa); + xmlFree (val); } static inline void @@ -278,9 +290,12 @@ read_humidity (GWeatherInfo *info, double percent; unit = xmlGetProp (node, XC("unit")); - if (unit == NULL || strcmp ((char*)unit, "%")) + if (unit == NULL || strcmp ((char*)unit, "%")) { + xmlFree (unit); return; + } + xmlFree (unit); val = xmlGetProp (node, XC("value")); if (val == NULL) return; @@ -288,6 +303,7 @@ read_humidity (GWeatherInfo *info, percent = g_ascii_strtod ((char*) val, NULL); info->priv->humidity = percent; info->priv->hasHumidity = TRUE; + xmlFree (val); } static inline void |