aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2010-04-08 20:05:18 +0800
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2010-04-08 21:51:51 +0800
commite303afdaf2cdfde7467cffd9b311074e205281f0 (patch)
tree599d7a9deb4cf29a557680ff0025e4e8937e6e90
parent093c7b7b64293adb9e8e31d08e557320a47dc757 (diff)
downloadgsoc2013-empathy-e303afdaf2cdfde7467cffd9b311074e205281f0.tar
gsoc2013-empathy-e303afdaf2cdfde7467cffd9b311074e205281f0.tar.gz
gsoc2013-empathy-e303afdaf2cdfde7467cffd9b311074e205281f0.tar.bz2
gsoc2013-empathy-e303afdaf2cdfde7467cffd9b311074e205281f0.tar.lz
gsoc2013-empathy-e303afdaf2cdfde7467cffd9b311074e205281f0.tar.xz
gsoc2013-empathy-e303afdaf2cdfde7467cffd9b311074e205281f0.tar.zst
gsoc2013-empathy-e303afdaf2cdfde7467cffd9b311074e205281f0.zip
geocode_cb: create a new location hash table instead of modifying the current one
The location we receive from tp-glib should be considered as read-only as we don't have any guarantee about the way keys and values are freed. Should hopefully fix (#615135).
-rw-r--r--libempathy/empathy-contact.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/libempathy/empathy-contact.c b/libempathy/empathy-contact.c
index 387370097..c2bdc6a7a 100644
--- a/libempathy/empathy-contact.c
+++ b/libempathy/empathy-contact.c
@@ -1231,10 +1231,11 @@ geocode_cb (GeoclueGeocode *geocode,
GError *error,
gpointer contact)
{
- GValue *new_value;
- GHashTable *location;
+ EmpathyContactPriv *priv = GET_PRIV (contact);
+ GHashTable *new_location;
- location = empathy_contact_get_location (EMPATHY_CONTACT (contact));
+ if (priv->location == NULL)
+ goto out;
if (error != NULL)
{
@@ -1249,23 +1250,31 @@ geocode_cb (GeoclueGeocode *geocode,
if (!(fields & GEOCLUE_POSITION_FIELDS_LONGITUDE))
goto out;
- g_hash_table_insert (location, g_strdup (EMPATHY_LOCATION_LAT),
- tp_g_value_slice_new_double (latitude));
- DEBUG ("\t - Latitude: %f", latitude);
+ new_location = tp_asv_new (
+ EMPATHY_LOCATION_LAT, G_TYPE_DOUBLE, latitude,
+ EMPATHY_LOCATION_LON, G_TYPE_DOUBLE, longitude,
+ NULL);
- g_hash_table_insert (location, g_strdup (EMPATHY_LOCATION_LON),
- tp_g_value_slice_new_double (longitude));
+ DEBUG ("\t - Latitude: %f", latitude);
DEBUG ("\t - Longitude: %f", longitude);
- if (fields & GEOCLUE_POSITION_FIELDS_ALTITUDE)
+ /* Copy remaning fields. LAT and LON were not defined so we won't overwrite
+ * the values we just set. */
+ tp_g_hash_table_update (new_location, priv->location,
+ (GBoxedCopyFunc) g_strdup, (GBoxedCopyFunc) tp_g_value_slice_dup);
+
+ /* Set the altitude only if it wasn't defined before */
+ if (fields & GEOCLUE_POSITION_FIELDS_ALTITUDE &&
+ g_hash_table_lookup (new_location, EMPATHY_LOCATION_LAT) == NULL)
{
- new_value = tp_g_value_slice_new_double (altitude);
- g_hash_table_replace (location, g_strdup (EMPATHY_LOCATION_ALT),
- new_value);
+ g_hash_table_insert (new_location, g_strdup (EMPATHY_LOCATION_ALT),
+ tp_g_value_slice_new_double (altitude));
DEBUG ("\t - Altitude: %f", altitude);
}
/* Don't change the accuracy as we used an address to get this position */
+ g_hash_table_unref (priv->location);
+ priv->location = new_location;
g_object_notify (contact, "location");
out:
g_object_unref (geocode);