]> git.street.me.uk Git - andy/viking.git/commitdiff
Red Hat Bugzilla – Bug 1210403: Only download and process one Bing attribution list.
authorRob Norris <rw_norris@hotmail.com>
Sat, 2 May 2015 10:51:45 +0000 (11:51 +0100)
committerRob Norris <rw_norris@hotmail.com>
Sat, 2 May 2015 10:51:45 +0000 (11:51 +0100)
If making more than one download request to get the Bing attributions,
 but then updating (and using) a single instance variable from multiple threads,
 results in undefined behaviour (i.e. could lead to crashes).

Thus ensure only one request at a time is made.

src/bingmapsource.c

index 7a3887ad4e2a2458f1ef7a4910bed6471401d0ee..917d5302586e4290d0f4dbb43f3ea6af9d4e6d91 100644 (file)
@@ -79,6 +79,7 @@ struct _BingMapSourcePrivate
        GList *attributions;
        /* Current attribution, when parsing */
        gchar *attribution;
+       gboolean loading_attributions;
 };
 
 /* The pixbuf to store the logo */
@@ -109,6 +110,7 @@ bing_map_source_init (BingMapSource *self)
        priv->api_key = NULL;
        priv->attributions = NULL;
        priv->attribution = NULL;
+       priv->loading_attributions = FALSE;
 }
 
 static void
@@ -297,7 +299,11 @@ _get_copyright(VikMapSource * self, LatLonBBox bbox, gdouble zoom, void (*fct)(V
        /* Loop over all known attributions */
        GList *attribution = priv->attributions;
        if (attribution == NULL && g_strcmp0 ("<no-set>", priv->api_key)) {
-               _async_load_attributions (BING_MAP_SOURCE (self));
+               if ( ! priv->loading_attributions )
+                       _async_load_attributions (BING_MAP_SOURCE (self));
+               else
+                       // Wait until attributions loaded before processing them
+                       return;
        }
        while (attribution != NULL) {
                struct _Attribution *current = (struct _Attribution*)attribution->data;
@@ -462,6 +468,7 @@ _load_attributions ( BingMapSource *self )
        }
 
 done:
+       priv->loading_attributions = FALSE;
        g_free(uri);
        g_remove(tmpname);
        g_free(tmpname);