summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaciej S. Szmigiero <maciej.szmigiero@oracle.com>2023-01-12 23:42:30 +0100
committerMaciej S. Szmigiero <maciej.szmigiero@oracle.com>2023-01-14 00:49:52 +0100
commit0cc334a44ed0384785379996e7f20e85f26e624f (patch)
treecf93acf750d4ac1e4813a5f742c28ac273a49ee1
parent3fc8fe101fd93605cb3d1e301ee8e552a9601338 (diff)
downloadgeoclue-0cc334a44ed0384785379996e7f20e85f26e624f.tar.gz
Remove manual GDateTime memory management
-rw-r--r--demo/where-am-i.c3
-rw-r--r--src/gclue-location.c17
2 files changed, 10 insertions, 10 deletions
diff --git a/demo/where-am-i.c b/demo/where-am-i.c
index a75441c..8324058 100644
--- a/demo/where-am-i.c
+++ b/demo/where-am-i.c
@@ -109,7 +109,7 @@ print_location (GClueSimple *simple)
timestamp = gclue_location_get_timestamp (location);
if (timestamp) {
- GDateTime *date_time;
+ g_autoptr(GDateTime) date_time = NULL;
guint64 sec, usec;
g_autofree gchar *str = NULL;
@@ -120,7 +120,6 @@ print_location (GClueSimple *simple)
str = g_date_time_format
(date_time,
"%c (%s seconds since the Epoch)");
- g_date_time_unref (date_time);
g_print ("Timestamp: %s\n", str);
}
diff --git a/src/gclue-location.c b/src/gclue-location.c
index b5f9869..51fff5f 100644
--- a/src/gclue-location.c
+++ b/src/gclue-location.c
@@ -484,14 +484,17 @@ parse_nmea_timestamp (const char *nmea_ts)
{
char parts[3][3];
int i, hours, minutes, seconds;
- GDateTime *now, *ts = NULL;
+ g_autoptr(GDateTime) now = NULL;
+ g_autoptr(GDateTime) ts = NULL;
guint64 ret;
now = g_date_time_new_now_utc ();
- ret = g_date_time_to_unix (now);
+ if (now == NULL) {
+ g_warning ("Failed to get the current UTC time");
+ return 0;
+ }
- if( now == NULL)
- goto parse_error;
+ ret = g_date_time_to_unix (now);
if (strlen (nmea_ts) < 6) {
if (strlen (nmea_ts) >= 1)
@@ -522,8 +525,8 @@ parse_nmea_timestamp (const char *nmea_ts)
if (g_date_time_difference (ts, now) > TIME_DIFF_THRESHOLD) {
g_debug ("NMEA timestamp '%s' in future. Assuming yesterday's.",
nmea_ts);
- g_date_time_unref (ts);
+ g_clear_pointer (&ts, g_date_time_unref);
ts = g_date_time_new_utc (g_date_time_get_year (now),
g_date_time_get_month (now),
g_date_time_get_day_of_month (now) - 1,
@@ -533,10 +536,8 @@ parse_nmea_timestamp (const char *nmea_ts)
}
ret = g_date_time_to_unix (ts);
- g_date_time_unref (ts);
-parse_error:
- g_date_time_unref (now);
+parse_error:
return ret;
}