Make regexp patterns for matching uris thread safe (fixes NB#108791)
authorJose Dapena Paz <jdapena@igalia.com>
Mon, 30 Mar 2009 17:14:44 +0000 (17:14 +0000)
committerJose Dapena Paz <jdapena@igalia.com>
Mon, 30 Mar 2009 17:14:44 +0000 (17:14 +0000)
pmo-trunk-r8473

src/modest-stream-text-to-html.c
src/modest-text-utils.c
src/modest-text-utils.h

index 50e1135..b62de15 100644 (file)
@@ -125,6 +125,7 @@ modest_stream_text_to_html_init (ModestStreamTextToHtml *obj)
        priv->linkify_limit = 0;
        priv->full_limit = 0;
        priv->total_output = 0;
+       modest_text_utils_hyperlinkify_begin ();
 }
 
 static void
@@ -139,6 +140,7 @@ modest_stream_text_to_html_finalize (GObject *obj)
        if (priv->line_buffer != NULL) {
                g_string_free (priv->line_buffer, TRUE);
        }
+       modest_text_utils_hyperlinkify_end ();
 }
 
 GObject*
index 7ec2073..93e51ee 100644 (file)
@@ -1042,6 +1042,7 @@ cmp_offsets_reverse (const url_match_t *match1, const url_match_t *match2)
 
 static gint url_matches_block = 0;
 static url_match_pattern_t patterns[] = MAIL_VIEWER_URL_MATCH_PATTERNS;
+static GMutex *url_patterns_mutex = NULL;
 
 
 static gboolean
@@ -1076,17 +1077,25 @@ free_patterns ()
 void
 modest_text_utils_hyperlinkify_begin (void)
 {
+
+       if (url_patterns_mutex == NULL) {
+               url_patterns_mutex = g_mutex_new ();
+       }
+       g_mutex_lock (url_patterns_mutex);
        if (url_matches_block == 0)
                compile_patterns ();
        url_matches_block ++;
+       g_mutex_unlock (url_patterns_mutex);
 }
 
 void
 modest_text_utils_hyperlinkify_end (void)
 {
+       g_mutex_lock (url_patterns_mutex);
        url_matches_block--;
        if (url_matches_block <= 0)
                free_patterns ();
+       g_mutex_unlock (url_patterns_mutex);
 }
 
 
index 22f94d8..f2d9659 100644 (file)
@@ -176,14 +176,14 @@ void     modest_text_utils_address_range_at_position (const gchar *recipients_li
 /**
  * modest_text_utils_hyperlinkify_begin:
  *
- * begin a linkify block, compiling the caches to be reused.
+ * begin a linkify block, compiling the caches to be reused. Use it in mainloop.
  */
 void modest_text_utils_hyperlinkify_begin (void);
 
 /**
  * modest_text_utils_hyperlinkify_end:
  *
- * end a linkify block, freeing the caches to be reused.
+ * end a linkify block, freeing the caches to be reused. Use it in mainloop.
  */
 void modest_text_utils_hyperlinkify_end (void);