From 3a00a6ff63e2fcd2feb005314753c6d4f32cf105 Mon Sep 17 00:00:00 2001 From: Jose Dapena Paz Date: Mon, 30 Mar 2009 17:14:44 +0000 Subject: [PATCH] Make regexp patterns for matching uris thread safe (fixes NB#108791) pmo-trunk-r8473 --- src/modest-stream-text-to-html.c | 2 ++ src/modest-text-utils.c | 9 +++++++++ src/modest-text-utils.h | 4 ++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/modest-stream-text-to-html.c b/src/modest-stream-text-to-html.c index 50e1135..b62de15 100644 --- a/src/modest-stream-text-to-html.c +++ b/src/modest-stream-text-to-html.c @@ -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* diff --git a/src/modest-text-utils.c b/src/modest-text-utils.c index 7ec2073..93e51ee 100644 --- a/src/modest-text-utils.c +++ b/src/modest-text-utils.c @@ -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); } diff --git a/src/modest-text-utils.h b/src/modest-text-utils.h index 22f94d8..f2d9659 100644 --- a/src/modest-text-utils.h +++ b/src/modest-text-utils.h @@ -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); -- 1.7.9.5