diff options
author | Ted Gould <ted@gould.cx> | 2011-02-01 09:39:28 -0600 |
---|---|---|
committer | Ted Gould <ted@gould.cx> | 2011-02-01 09:39:28 -0600 |
commit | 96ab5fe4d0dc4d8221e05116f6babcaf66cf2379 (patch) | |
tree | 4936fe8fdf01c2768e6304c812e07bbd9b22c271 /src | |
parent | 004f46321f23d5967f698dd1201bc19b8a422dbf (diff) | |
download | ayatana-indicator-datetime-96ab5fe4d0dc4d8221e05116f6babcaf66cf2379.tar.gz ayatana-indicator-datetime-96ab5fe4d0dc4d8221e05116f6babcaf66cf2379.tar.bz2 ayatana-indicator-datetime-96ab5fe4d0dc4d8221e05116f6babcaf66cf2379.zip |
Put the geo_address clean up in a small helper function.
Diffstat (limited to 'src')
-rw-r--r-- | src/datetime-service.c | 33 |
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, |