aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/datetime-service.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/src/datetime-service.c b/src/datetime-service.c
index db887a9..2a9ccdb 100644
--- a/src/datetime-service.c
+++ b/src/datetime-service.c
@@ -384,6 +384,23 @@ geo_address_cb (GeoclueAddress * address, int timestamp, GHashTable * addy_data,
return;
}
+/* Clean up the reference we kept to the address and make sure to
+ drop the signals incase someone else has one. */
+static void
+geo_address_clean (void)
+{
+ if (geo_address == NULL) {
+ return;
+ }
+
+ g_signal_handlers_disconnect_by_func(G_OBJECT(geo_address), geo_address_cb, NULL);
+ g_object_unref(G_OBJECT(geo_address));
+
+ geo_address = NULL;
+
+ return;
+}
+
/* Callback from creating the address */
static void
geo_create_address (GeoclueMasterClient * master, GeoclueAddress * address, GError * error, gpointer user_data)
@@ -397,6 +414,7 @@ geo_create_address (GeoclueMasterClient * master, GeoclueAddress * address, GErr
so this is a warning. But, it really is only a mem-leak so we
don't need to error out. */
g_warn_if_fail(geo_address == NULL);
+ geo_address_clean();
g_debug("Created Geoclue Address");
geo_address = address;
@@ -427,10 +445,7 @@ geo_client_invalid (GeoclueMasterClient * client, gpointer user_data)
/* Client changes we can assume the address is now invalid so we
need to unreference the one we had. */
- if (geo_address != NULL) {
- g_object_unref(G_OBJECT(geo_address));
- }
- geo_address = NULL;
+ geo_address_clean();
/* And our master client is invalid */
if (geo_master != NULL) {
@@ -459,10 +474,7 @@ geo_address_change (GeoclueMasterClient * client, gchar * a, gchar * b, gchar *
/* If the address is supposed to have changed we need to drop the old
address before starting to get the new one. */
- if (geo_address != NULL) {
- g_object_unref(G_OBJECT(geo_address));
- }
- geo_address = NULL;
+ geo_address_clean();
geoclue_master_client_create_address_async(geo_master, geo_create_address, NULL);
@@ -486,10 +498,7 @@ geo_create_client (GeoclueMaster * master, GeoclueMasterClient * client, gchar *
g_object_ref(G_OBJECT(geo_master));
/* New client, make sure we don't have an address hanging on */
- if (geo_address != NULL) {
- g_object_unref(G_OBJECT(geo_address));
- }
- geo_address = NULL;
+ geo_address_clean();
geoclue_master_client_set_requirements_async(geo_master,
GEOCLUE_ACCURACY_LEVEL_REGION,