return FALSE;
}
- key = g_slice_alloc (sizeof (*key));
+ key = rspamd_mempool_alloc0 (pool, sizeof (*key));
key->key = kp;
- keystat = g_slice_alloc0 (sizeof (*keystat));
+ keystat = rspamd_mempool_alloc0 (pool, sizeof (*keystat));
/* Hash of ip -> fuzzy_key_stat */
keystat->last_ips = rspamd_lru_hash_new_full (1024,
(GDestroyNotify)rspamd_inet_address_destroy, fuzzy_key_stat_dtor,
ctx->keypair_cache_size = DEFAULT_KEYPAIR_CACHE_SIZE;
ctx->keys = g_hash_table_new_full (fuzzy_kp_hash, fuzzy_kp_equal,
NULL, fuzzy_key_dtor);
+ rspamd_mempool_add_destructor (cfg->cfg_pool,
+ (rspamd_mempool_destruct_t)g_hash_table_unref, ctx->keys);
ctx->master_flags = g_hash_table_new (g_direct_hash, g_direct_equal);
+ rspamd_mempool_add_destructor (cfg->cfg_pool,
+ (rspamd_mempool_destruct_t)g_hash_table_unref, ctx->master_flags);
ctx->errors_ips = rspamd_lru_hash_new_full (1024,
(GDestroyNotify) rspamd_inet_address_destroy, g_free,
rspamd_inet_address_hash, rspamd_inet_address_equal);
+ rspamd_mempool_add_destructor (cfg->cfg_pool,
+ (rspamd_mempool_destruct_t)rspamd_lru_hash_destroy, ctx->errors_ips);
ctx->cfg = cfg;
ctx->mirrors = g_ptr_array_new ();
+ rspamd_mempool_add_destructor (cfg->cfg_pool,
+ (rspamd_mempool_destruct_t)rspamd_ptr_array_free_hard, ctx->mirrors);
ctx->updates_maxfail = DEFAULT_UPDATES_MAXFAIL;
rspamd_rcl_register_worker_option (cfg,
rspamd_keypair_cache_destroy (ctx->keypair_cache);
}
- rspamd_lru_hash_destroy (ctx->errors_ips);
-
g_hash_table_unref (ctx->keys);
REF_RELEASE (ctx->cfg);
}
struct rspamd_function_atom *
-rspamd_mime_expr_parse_function_atom (const gchar *input)
+rspamd_mime_expr_parse_function_atom (rspamd_mempool_t *pool, const gchar *input)
{
const gchar *obrace, *ebrace, *p, *c;
gchar t, *databuf;
g_assert (obrace != NULL && ebrace != NULL);
- res = g_slice_alloc0 (sizeof (*res));
- res->name = g_malloc (obrace - input + 1);
+ res = rspamd_mempool_alloc0 (pool, sizeof (*res));
+ res->name = rspamd_mempool_alloc (pool, obrace - input + 1);
rspamd_strlcpy (res->name, input, obrace - input + 1);
res->args = g_array_new (FALSE, FALSE, sizeof (struct expression_argument));
+ rspamd_mempool_add_destructor (pool, rspamd_array_free_hard, res->args);
p = obrace + 1;
c = p;
}
else if (t == ',' || p == ebrace) {
len = p - c + 1;
- databuf = g_malloc (len);
+ databuf = rspamd_mempool_alloc (pool, len);
rspamd_strlcpy (databuf, c, len);
arg.type = EXPRESSION_ARGUMENT_REGEXP;
arg.data = rspamd_regexp_cache_create (NULL, databuf, NULL, &err);
len = p - c + 1;
}
- databuf = g_malloc (len);
+ databuf = rspamd_mempool_alloc (pool, len);
rspamd_strlcpy (databuf, c, len);
arg.type = EXPRESSION_ARGUMENT_NORMAL;
arg.data = databuf;
lua_pop (cfg->lua_state, 1);
}
else {
- mime_atom->d.func = rspamd_mime_expr_parse_function_atom (mime_atom->str);
+ mime_atom->d.func = rspamd_mime_expr_parse_function_atom (pool,
+ mime_atom->str);
if (mime_atom->d.func == NULL) {
g_set_error (err, rspamd_mime_expr_quark(), 200, "cannot parse function '%s'",
mime_atom->str);
}
else {
parent_doc = (*top)->doc_ref;
- new->doc_ref = rspamd_rcl_add_doc_obj (parent_doc,
+ new->doc_ref = ucl_object_ref (rspamd_rcl_add_doc_obj (parent_doc,
NULL,
name,
type,
NULL,
0,
NULL,
- 0);
+ 0));
}
HASH_ADD_KEYPTR (hh, *top, new->name, strlen (new->name), new);
new->type = type;
new->strict_type = strict_type;
- new->doc_ref = rspamd_rcl_add_doc_obj (doc_target,
+ new->doc_ref = ucl_object_ref (rspamd_rcl_add_doc_obj (doc_target,
doc_string,
name,
type,
NULL,
0,
NULL,
- 0);
+ 0));
HASH_ADD_KEYPTR (hh, *top, new->name, strlen (new->name), new);
return new;
ucl_object_insert_key (doc_target, doc_obj, doc_name, 0, true);
- return ucl_object_ref (doc_obj);
+ return doc_obj;
}
ucl_object_t *
}
}
- return rspamd_rcl_add_doc_obj ((ucl_object_t *) cur,
+ return rspamd_rcl_add_doc_obj (ucl_object_ref (cur),
doc_string,
doc_name,
type,
return 1;
}
+
+struct rspamd_lua_ref_cbdata {
+ lua_State *L;
+ gint cbref;
+};
+
+static void
+rspamd_lua_ref_dtor (gpointer p)
+{
+ struct rspamd_lua_ref_cbdata *cbdata = p;
+
+ luaL_unref (cbdata->L, LUA_REGISTRYINDEX, cbdata->cbref);
+}
+
+void
+rspamd_lua_add_ref_dtor (lua_State *L, rspamd_mempool_t *pool,
+ gint ref)
+{
+ struct rspamd_lua_ref_cbdata *cbdata;
+
+ if (ref != -1) {
+ cbdata = rspamd_mempool_alloc (pool, sizeof (*cbdata));
+ cbdata->cbref = ref;
+ cbdata->L = L;
+
+ rspamd_mempool_add_destructor (pool, rspamd_lua_ref_dtor, cbdata);
+ }
+}
gboolean rspamd_lua_run_postloads (lua_State *L, struct rspamd_config *cfg,
struct event_base *ev_base, struct rspamd_worker *w);
+/**
+ * Adds new destructor for a local function for specific pool
+ * @param L
+ * @param pool
+ * @param ref
+ */
+void rspamd_lua_add_ref_dtor (lua_State *L, rspamd_mempool_t *pool,
+ gint ref);
+
#endif /* WITH_LUA */
#endif /* RSPAMD_LUA_H */
if (lua_type (cfg->lua_state, -1) == LUA_TFUNCTION) {
dkim_module_ctx->sign_condition_ref = luaL_ref (cfg->lua_state,
LUA_REGISTRYINDEX);
+ rspamd_lua_add_ref_dtor (cfg->lua_state,
+ dkim_module_ctx->dkim_pool,
+ dkim_module_ctx->sign_condition_ref);
dkim_module_ctx->dkim_sign_hash = rspamd_lru_hash_new (
128,
saved_ctx = dkim_module_ctx->ctx;
rspamd_mempool_delete (dkim_module_ctx->dkim_pool);
radix_destroy_compressed (dkim_module_ctx->whitelist_ip);
+
if (dkim_module_ctx->dkim_domains) {
g_hash_table_destroy (dkim_module_ctx->dkim_domains);
}
+ if (dkim_module_ctx->dkim_hash) {
+ rspamd_lru_hash_destroy (dkim_module_ctx->dkim_hash);
+ }
+
+ if (dkim_module_ctx->dkim_sign_hash) {
+ rspamd_lru_hash_destroy (dkim_module_ctx->dkim_sign_hash);
+ }
+
memset (dkim_module_ctx, 0, sizeof (*dkim_module_ctx));
dkim_module_ctx->ctx = saved_ctx;
dkim_module_ctx->dkim_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "dkim");
saved_ctx = spf_module_ctx->ctx;
rspamd_mempool_delete (spf_module_ctx->spf_pool);
+ rspamd_lru_hash_destroy (spf_module_ctx->spf_hash);
radix_destroy_compressed (spf_module_ctx->whitelist_ip);
memset (spf_module_ctx, 0, sizeof (*spf_module_ctx));
spf_module_ctx->ctx = saved_ctx;
return FALSE;
}
- up = g_malloc0 (sizeof (*up));
- rspamd_mempool_add_destructor (pool,
- (rspamd_mempool_destruct_t)g_free, up);
+ up = rspamd_mempool_alloc0 (pool, sizeof (*up));
up->parser_from_ref = -1;
up->parser_to_ref = -1;
up->name = rspamd_mempool_strdup (pool, ucl_object_tostring (elt));
&up->parser_to_ref, err)) {
goto err;
}
+
+ rspamd_lua_add_ref_dtor (L, pool, up->parser_from_ref);
+ rspamd_lua_add_ref_dtor (L, pool, up->parser_to_ref);
}
double_to_tv (up->timeout, &up->io_tv);
return FALSE;
}
- up = g_malloc0 (sizeof (*up));
- rspamd_mempool_add_destructor (pool,
- (rspamd_mempool_destruct_t)g_free, up);
+ up = rspamd_mempool_alloc0 (pool, sizeof (*up));
up->name = rspamd_mempool_strdup (pool, ucl_object_tostring (elt));
up->parser_to_ref = -1;
up->parser_from_ref = -1;
&up->parser_to_ref, err)) {
goto err;
}
+
+ rspamd_lua_add_ref_dtor (L, pool, up->parser_from_ref);
+ rspamd_lua_add_ref_dtor (L, pool, up->parser_to_ref);
}
elt = ucl_object_lookup_any (obj, "settings", "settings_id", NULL);