diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-02-05 15:09:23 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-02-05 15:09:23 +0000 |
commit | b4cda5986a7c1f234fe670f7c9e32736ecc1fd61 (patch) | |
tree | f0ecd6beb96d490af564026ab51ca66a034bfaa9 | |
parent | 529089bab628319a7f3b7d50d070342421670af4 (diff) | |
download | rspamd-b4cda5986a7c1f234fe670f7c9e32736ecc1fd61.tar.gz rspamd-b4cda5986a7c1f234fe670f7c9e32736ecc1fd61.zip |
[Minor] Plug memory leak
-rw-r--r-- | src/lua/lua_mimepart.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c index 9cc1374be..c12485ecb 100644 --- a/src/lua/lua_mimepart.c +++ b/src/lua/lua_mimepart.c @@ -1181,6 +1181,11 @@ struct lua_shingle_data { rspamd_ftok_t t3; }; +struct lua_shingle_filter_cbdata { + struct rspamd_mime_text_part *part; + rspamd_mempool_t *pool; +}; + #define STORE_TOKEN(i, t) do { \ if ((i) < part->utf_words->len) { \ word = &g_array_index (part->utf_words, rspamd_stat_token_t, (i)); \ @@ -1197,7 +1202,10 @@ lua_shingles_filter (guint64 *input, gsize count, gsize i, min_idx = 0; struct lua_shingle_data *sd; rspamd_stat_token_t *word; - struct rspamd_mime_text_part *part = (struct rspamd_mime_text_part *)ud; + struct lua_shingle_filter_cbdata *cbd = (struct lua_shingle_filter_cbdata *)ud; + struct rspamd_mime_text_part *part; + + part = cbd->part; for (i = 0; i < count; i ++) { if (minimal > input[i]) { @@ -1206,7 +1214,7 @@ lua_shingles_filter (guint64 *input, gsize count, } } - sd = g_malloc0 (sizeof (*sd)); + sd = rspamd_mempool_alloc0 (cbd->pool, sizeof (*sd)); sd->hash = minimal; @@ -1232,6 +1240,7 @@ lua_textpart_get_fuzzy_hashes (lua_State * L) struct lua_shingle_data *sd; rspamd_cryptobox_hash_state_t st; rspamd_stat_token_t *word; + struct lua_shingle_filter_cbdata cbd; if (part && pool) { /* TODO: add keys and algorithms support */ @@ -1254,8 +1263,10 @@ lua_textpart_get_fuzzy_hashes (lua_State * L) sizeof (hexdigest)); lua_pushlstring (L, hexdigest, sizeof (hexdigest) - 1); + cbd.pool = pool; + cbd.part = part; sgl = rspamd_shingles_from_text (part->utf_words, key, - pool, lua_shingles_filter, part, RSPAMD_SHINGLES_MUMHASH); + pool, lua_shingles_filter, &cbd, RSPAMD_SHINGLES_MUMHASH); if (sgl == NULL) { lua_pushnil (L); |