commit 7e8b8d1: [Minor] Plug more leaks

Vsevolod Stakhov vsevolod at highsecure.ru
Wed Jun 26 12:07:06 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-06-26 13:04:32 +0100
URL: https://github.com/rspamd/rspamd/commit/7e8b8d1cbba46acabe7d2883bacf6c2661977d1b (HEAD -> master)

[Minor] Plug more leaks

---
 src/libmime/lang_detection.c    | 9 ++-------
 src/libserver/rspamd_symcache.c | 1 +
 src/libserver/task.c            | 2 +-
 src/libutil/map.c               | 2 ++
 4 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/src/libmime/lang_detection.c b/src/libmime/lang_detection.c
index bb00fb31d..3f2a50134 100644
--- a/src/libmime/lang_detection.c
+++ b/src/libmime/lang_detection.c
@@ -494,7 +494,8 @@ rspamd_language_detector_read_file (struct rspamd_config *cfg,
 					rspamd_ftok_t *tok;
 					gchar *dst;
 
-					tok = g_malloc (sizeof (*tok) + wlen + 1);
+					tok = rspamd_mempool_alloc (cfg->cfg_pool,
+							sizeof (*tok) + wlen + 1);
 					dst = ((gchar *)tok) + sizeof (*tok);
 					rspamd_strlcpy (dst, saved, wlen + 1);
 					tok->begin = dst;
@@ -737,8 +738,6 @@ static void
 rspamd_language_detector_dtor (struct rspamd_lang_detector *d)
 {
 	if (d) {
-		rspamd_ftok_t *tok;
-
 		for (guint i = 0; i < RSPAMD_LANGUAGE_MAX; i ++) {
 			kh_destroy (rspamd_trigram_hash, d->trigramms[i]);
 			rspamd_multipattern_destroy (d->stop_words[i].mp);
@@ -749,10 +748,6 @@ rspamd_language_detector_dtor (struct rspamd_lang_detector *d)
 			g_ptr_array_free (d->languages, TRUE);
 		}
 
-		kh_foreach_key (d->stop_words_norm, tok, {
-			g_free (tok); /* String is embedded and freed automatically */
-		});
-
 		kh_destroy (rspamd_stopwords_hash, d->stop_words_norm);
 	}
 }
diff --git a/src/libserver/rspamd_symcache.c b/src/libserver/rspamd_symcache.c
index 943987cc6..59423368e 100644
--- a/src/libserver/rspamd_symcache.c
+++ b/src/libserver/rspamd_symcache.c
@@ -1149,6 +1149,7 @@ rspamd_symcache_destroy (struct rspamd_symcache *cache)
 		g_ptr_array_free (cache->postfilters, TRUE);
 		g_ptr_array_free (cache->idempotent, TRUE);
 		g_ptr_array_free (cache->composites, TRUE);
+		g_ptr_array_free (cache->virtual, TRUE);
 		REF_RELEASE (cache->items_by_order);
 
 		if (cache->peak_cb != -1) {
diff --git a/src/libserver/task.c b/src/libserver/task.c
index 04be61744..4017b0094 100644
--- a/src/libserver/task.c
+++ b/src/libserver/task.c
@@ -271,7 +271,7 @@ rspamd_task_free (struct rspamd_task *task)
 				g_array_free (tp->normalized_hashes, TRUE);
 			}
 			if (tp->languages) {
-				g_ptr_array_unref (tp->languages);
+				g_ptr_array_free (tp->languages, TRUE);
 			}
 		}
 
diff --git a/src/libutil/map.c b/src/libutil/map.c
index 9f43fa253..458d298dd 100644
--- a/src/libutil/map.c
+++ b/src/libutil/map.c
@@ -1178,8 +1178,10 @@ rspamd_map_periodic_callback (struct ev_loop *loop, ev_timer *w, int revents)
 {
 	struct map_periodic_cbdata *cbd = (struct map_periodic_cbdata *)w->data;
 
+	MAP_RETAIN (cbd, "periodic");
 	ev_timer_stop (loop, w);
 	rspamd_map_process_periodic (cbd);
+	MAP_RELEASE (cbd, "periodic");
 }
 
 static void


More information about the Commits mailing list