summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2021-11-12 13:34:46 +0000
committerEmmanuele Bassi <ebassi@gnome.org>2021-11-12 14:06:11 +0000
commita610e6dffd19f0b3d42956fbe693971db047bc60 (patch)
treeb4a2133c143ce79f58cd6a972f1495a1f630601f
parent629081baf655c2ffc6df7b03073045b023ec8b36 (diff)
downloadlibgweather-a610e6dffd19f0b3d42956fbe693971db047bc60.tar.gz
Keep a reference while iterating on a location
This avoids an unused variable declaration when the first argument is NULL.
-rw-r--r--libgweather/gweather-location.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/libgweather/gweather-location.c b/libgweather/gweather-location.c
index a5cfe40..26cc30b 100644
--- a/libgweather/gweather-location.c
+++ b/libgweather/gweather-location.c
@@ -647,7 +647,10 @@ find_nearest_city (GWeatherLocation *location,
{
struct FindNearestCityData *data = user_data;
- double distance = location_distance (location->latitude, location->longitude, data->latitude, data->longitude);
+ double distance = location_distance (location->latitude,
+ location->longitude,
+ data->latitude,
+ data->longitude);
if (data->location == NULL || data->distance > distance) {
g_clear_pointer (&data->location, gweather_location_unref);
@@ -689,6 +692,8 @@ gweather_location_find_nearest_city (GWeatherLocation *loc,
if (loc == NULL)
loc = world = gweather_location_get_world ();
+ else
+ gweather_location_ref (loc);
lat = lat * M_PI / 180.0;
lon = lon * M_PI / 180.0;
@@ -700,6 +705,9 @@ gweather_location_find_nearest_city (GWeatherLocation *loc,
foreach_city (loc, (GFunc) find_nearest_city, &data, NULL, NULL, NULL);
+ if (loc != world)
+ gweather_location_unref (loc);
+
return data.location;
}
@@ -745,6 +753,8 @@ gweather_location_find_nearest_city_full (GWeatherLocation *loc,
if (loc == NULL)
loc = world = gweather_location_get_world ();
+ else
+ gweather_location_ref (loc);
lat = lat * M_PI / 180.0;
lon = lon * M_PI / 180.0;
@@ -758,6 +768,9 @@ gweather_location_find_nearest_city_full (GWeatherLocation *loc,
destroy (user_data);
+ if (loc != world)
+ gweather_location_unref (loc);
+
return gweather_location_ref (data.location);
}