[libgweather/static-fixes: 2/7] Keep a reference while iterating on a location
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgweather/static-fixes: 2/7] Keep a reference while iterating on a location
- Date: Fri, 12 Nov 2021 14:07:51 +0000 (UTC)
commit a610e6dffd19f0b3d42956fbe693971db047bc60
Author: Emmanuele Bassi <ebassi gnome org>
Date: Fri Nov 12 13:34:46 2021 +0000
Keep a reference while iterating on a location
This avoids an unused variable declaration when the first argument is
NULL.
libgweather/gweather-location.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
---
diff --git a/libgweather/gweather-location.c b/libgweather/gweather-location.c
index a5cfe404..26cc30b5 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);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]