diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-09-27 13:32:42 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-09-27 13:32:42 +0100 |
commit | 82637e89647924b395c4d4cdfc835ceebbd0b661 (patch) | |
tree | cbb2d71b9a16095b642bca1d6b3e27677b39aaa0 /src/libutil/regexp.c | |
parent | f2e9665d05f6e81603ef0e10dfbc161151357468 (diff) | |
download | rspamd-82637e89647924b395c4d4cdfc835ceebbd0b661.tar.gz rspamd-82637e89647924b395c4d4cdfc835ceebbd0b661.zip |
[Rework] Rework initialisation to reduce static leaks count
Diffstat (limited to 'src/libutil/regexp.c')
-rw-r--r-- | src/libutil/regexp.c | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/src/libutil/regexp.c b/src/libutil/regexp.c index fa606273c..6f449539f 100644 --- a/src/libutil/regexp.c +++ b/src/libutil/regexp.c @@ -998,7 +998,7 @@ rspamd_regexp_cache_create (struct rspamd_regexp_cache *cache, res = rspamd_regexp_new (pattern, flags, err); if (res) { - REF_RETAIN (res); + /* REF_RETAIN (res); */ g_hash_table_insert (cache->tbl, res->id, res); } @@ -1058,6 +1058,24 @@ rspamd_regexp_cache_destroy (struct rspamd_regexp_cache *cache) } } +RSPAMD_CONSTRUCTOR (rspamd_re_static_pool_ctor) +{ + global_re_cache = rspamd_regexp_cache_new (); +#ifdef WITH_PCRE2 + pcre2_ctx = pcre2_compile_context_create (NULL); + pcre2_set_newline (pcre2_ctx, PCRE_FLAG(NEWLINE_ANY)); +#endif +} + +RSPAMD_DESTRUCTOR (rspamd_re_static_pool_dtor) +{ + rspamd_regexp_cache_destroy (global_re_cache); +#ifdef WITH_PCRE2 + pcre2_compile_context_free (pcre2_ctx); +#endif +} + + void rspamd_regexp_library_init (struct rspamd_config *cfg) { @@ -1066,19 +1084,16 @@ rspamd_regexp_library_init (struct rspamd_config *cfg) can_jit = FALSE; check_jit = FALSE; } + else if (!can_jit) { + check_jit = TRUE; + } } - if (global_re_cache == NULL) { - global_re_cache = rspamd_regexp_cache_new (); + if (check_jit) { #ifdef HAVE_PCRE_JIT gint jit, rc; gchar *str; - if (check_jit) { -#ifdef WITH_PCRE2 - pcre2_ctx = pcre2_compile_context_create (NULL); - pcre2_set_newline (pcre2_ctx, PCRE_FLAG(NEWLINE_ANY)); -#endif #ifndef WITH_PCRE2 rc = pcre_config (PCRE_CONFIG_JIT, &jit); #else @@ -1118,23 +1133,12 @@ rspamd_regexp_library_init (struct rspamd_config *cfg) " are impossible"); can_jit = FALSE; } - } #else msg_info ("pcre is too old and has no JIT support, so many optimizations" - " are impossible"); + " are impossible"); can_jit = FALSE; #endif - } -} - -void -rspamd_regexp_library_finalize (void) -{ - if (global_re_cache != NULL) { - rspamd_regexp_cache_destroy (global_re_cache); -#ifdef WITH_PCRE2 - pcre2_compile_context_free (pcre2_ctx); -#endif + check_jit = FALSE; } } |