aboutsummaryrefslogtreecommitdiffstats
path: root/src/libmime
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-06-14 13:00:44 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-06-14 15:15:19 +0100
commit904c6caebe5da551be410d88aa4dd86039f03a4c (patch)
tree79cce46fcded2821fef79ea3e9fb81101ba0fe65 /src/libmime
parent7406e60b74327df055f3bacfc478bd5cb68fd6c9 (diff)
downloadrspamd-904c6caebe5da551be410d88aa4dd86039f03a4c.tar.gz
rspamd-904c6caebe5da551be410d88aa4dd86039f03a4c.zip
[Fix] Free language detector structures
Diffstat (limited to 'src/libmime')
-rw-r--r--src/libmime/lang_detection.c48
-rw-r--r--src/libmime/lang_detection.h4
2 files changed, 52 insertions, 0 deletions
diff --git a/src/libmime/lang_detection.c b/src/libmime/lang_detection.c
index 84d23ac63..8763365af 100644
--- a/src/libmime/lang_detection.c
+++ b/src/libmime/lang_detection.c
@@ -188,6 +188,7 @@ struct rspamd_lang_detector {
UConverter *uchar_converter;
gsize short_text_limit;
gsize total_occurencies; /* number of all languages found */
+ ref_entry_t ref;
};
static void
@@ -622,6 +623,32 @@ rspamd_language_detector_process_chain (struct rspamd_config *cfg,
}
}
+static void
+rspamd_language_detector_dtor (struct rspamd_lang_detector *d)
+{
+ if (d) {
+ if (d->uchar_converter) {
+ ucnv_close (d->uchar_converter);
+ }
+
+ if (d->unicode_scripts) {
+ g_hash_table_unref (d->unicode_scripts);
+ }
+
+ if (d->unigramms) {
+ kh_destroy (rspamd_unigram_hash, d->unigramms);
+ }
+
+ if (d->trigramms) {
+ kh_destroy (rspamd_trigram_hash, d->trigramms);
+ }
+
+ if (d->languages) {
+ g_ptr_array_free (d->languages, TRUE);
+ }
+ }
+}
+
struct rspamd_lang_detector*
rspamd_language_detector_init (struct rspamd_config *cfg)
{
@@ -702,6 +729,12 @@ rspamd_language_detector_init (struct rspamd_config *cfg)
(gint)g_hash_table_size (ret->unicode_scripts),
(gint)kh_size (ret->unigramms),
(gint)kh_size (ret->trigramms));
+
+ REF_INIT_RETAIN (ret, rspamd_language_detector_dtor);
+ rspamd_mempool_add_destructor (cfg->cfg_pool,
+ (rspamd_mempool_destruct_t)rspamd_language_detector_unref,
+ ret);
+
end:
if (gl.gl_pathc > 0) {
globfree (&gl);
@@ -1399,3 +1432,18 @@ rspamd_language_detector_detect (struct rspamd_task *task,
return result;
}
+
+
+struct rspamd_lang_detector*
+rspamd_language_detector_ref (struct rspamd_lang_detector* d)
+{
+ REF_RETAIN (d);
+
+ return d;
+}
+
+void
+rspamd_language_detector_unref (struct rspamd_lang_detector* d)
+{
+ REF_RELEASE (d);
+} \ No newline at end of file
diff --git a/src/libmime/lang_detection.h b/src/libmime/lang_detection.h
index 0058801b8..2d28ec65a 100644
--- a/src/libmime/lang_detection.h
+++ b/src/libmime/lang_detection.h
@@ -37,6 +37,10 @@ struct rspamd_lang_detector_res {
* @return
*/
struct rspamd_lang_detector* rspamd_language_detector_init (struct rspamd_config *cfg);
+
+struct rspamd_lang_detector* rspamd_language_detector_ref (struct rspamd_lang_detector* d);
+void rspamd_language_detector_unref (struct rspamd_lang_detector* d);
+
/**
* Convert string from utf8 to ucs32
* @param d