aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/controller.c13
-rw-r--r--src/libserver/task.c17
-rw-r--r--src/libserver/task.h6
-rw-r--r--src/lua/lua_util.c2
-rw-r--r--src/plugins/fuzzy_check.c2
-rw-r--r--src/rspamadm/lua_repl.c2
-rw-r--r--src/rspamd_proxy.c2
-rw-r--r--src/worker.c4
8 files changed, 31 insertions, 17 deletions
diff --git a/src/controller.c b/src/controller.c
index 9806e119e..052525750 100644
--- a/src/controller.c
+++ b/src/controller.c
@@ -1464,7 +1464,8 @@ rspamd_controller_handle_lua_history (lua_State *L,
lua_gettable (L, -2);
if (lua_isfunction (L, -1)) {
- task = rspamd_task_new (session->ctx->worker, session->cfg);
+ task = rspamd_task_new (session->ctx->worker, session->cfg,
+ NULL);
task->resolver = ctx->resolver;
task->ev_base = ctx->ev_base;
@@ -1762,7 +1763,7 @@ rspamd_controller_handle_lua (struct rspamd_http_connection_entry *conn_ent,
return 0;
}
- task = rspamd_task_new (session->ctx->worker, session->cfg);
+ task = rspamd_task_new (session->ctx->worker, session->cfg, NULL);
task->resolver = ctx->resolver;
task->ev_base = ctx->ev_base;
@@ -1945,7 +1946,7 @@ rspamd_controller_handle_learn_common (
return 0;
}
- task = rspamd_task_new (session->ctx->worker, session->cfg);
+ task = rspamd_task_new (session->ctx->worker, session->cfg, NULL);
task->resolver = ctx->resolver;
task->ev_base = ctx->ev_base;
@@ -2045,7 +2046,7 @@ rspamd_controller_handle_scan (struct rspamd_http_connection_entry *conn_ent,
return 0;
}
- task = rspamd_task_new (session->ctx->worker, session->cfg);
+ task = rspamd_task_new (session->ctx->worker, session->cfg, NULL);
task->ev_base = session->ctx->ev_base;
task->resolver = ctx->resolver;
@@ -2543,7 +2544,7 @@ rspamd_controller_handle_stat_common (
rspamd_mempool_stat (&mem_st);
memcpy (&stat_copy, session->ctx->worker->srv->stat, sizeof (stat_copy));
stat = &stat_copy;
- task = rspamd_task_new (session->ctx->worker, session->cfg);
+ task = rspamd_task_new (session->ctx->worker, session->cfg, NULL);
ctx = session->ctx;
task->resolver = ctx->resolver;
@@ -2877,7 +2878,7 @@ rspamd_controller_handle_lua_plugin (struct rspamd_http_connection_entry *conn_e
return 0;
}
- task = rspamd_task_new (session->ctx->worker, session->cfg);
+ task = rspamd_task_new (session->ctx->worker, session->cfg, NULL);
task->resolver = ctx->resolver;
task->ev_base = ctx->ev_base;
diff --git a/src/libserver/task.c b/src/libserver/task.c
index 2c9f134bc..3c8eeb24e 100644
--- a/src/libserver/task.c
+++ b/src/libserver/task.c
@@ -60,7 +60,8 @@ rspamd_request_header_dtor (gpointer p)
* Create new task
*/
struct rspamd_task *
-rspamd_task_new (struct rspamd_worker *worker, struct rspamd_config *cfg)
+rspamd_task_new (struct rspamd_worker *worker, struct rspamd_config *cfg,
+ rspamd_mempool_t *pool)
{
struct rspamd_task *new_task;
@@ -82,7 +83,14 @@ rspamd_task_new (struct rspamd_worker *worker, struct rspamd_config *cfg)
new_task->time_real = rspamd_get_ticks ();
new_task->time_virtual = rspamd_get_virtual_ticks ();
- new_task->task_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "task");
+ if (pool == NULL) {
+ new_task->task_pool =
+ rspamd_mempool_new (rspamd_mempool_suggest_size (), "task");
+ new_task->flags |= RSPAMD_TASK_FLAG_OWN_POOL;
+ }
+ else {
+ new_task->task_pool = pool;
+ }
new_task->raw_headers = g_hash_table_new_full (rspamd_strcase_hash,
rspamd_strcase_equal, NULL, rspamd_ptr_array_free_hard);
@@ -295,7 +303,10 @@ rspamd_task_free (struct rspamd_task *task)
REF_RELEASE (task->cfg);
}
- rspamd_mempool_delete (task->task_pool);
+ if (task->flags & RSPAMD_TASK_FLAG_OWN_POOL) {
+ rspamd_mempool_delete (task->task_pool);
+ }
+
g_slice_free1 (sizeof (struct rspamd_task), task);
}
}
diff --git a/src/libserver/task.h b/src/libserver/task.h
index 549c49989..cc1cc492a 100644
--- a/src/libserver/task.h
+++ b/src/libserver/task.h
@@ -106,6 +106,7 @@ enum rspamd_task_stage {
#define RSPAMD_TASK_FLAG_COMPRESSED (1 << 24)
#define RSPAMD_TASK_FLAG_PROFILE (1 << 25)
#define RSPAMD_TASK_FLAG_GREYLISTED (1 << 26)
+#define RSPAMD_TASK_FLAG_OWN_POOL (1 << 27)
#define RSPAMD_TASK_IS_SKIPPED(task) (((task)->flags & RSPAMD_TASK_FLAG_SKIP))
#define RSPAMD_TASK_IS_JSON(task) (((task)->flags & RSPAMD_TASK_FLAG_JSON))
@@ -205,8 +206,9 @@ struct rspamd_task {
/**
* Construct new task for worker
*/
-struct rspamd_task * rspamd_task_new (struct rspamd_worker *worker,
- struct rspamd_config *cfg);
+struct rspamd_task *rspamd_task_new (struct rspamd_worker *worker,
+ struct rspamd_config *cfg,
+ rspamd_mempool_t *pool);
/**
* Destroy task object and remove its IO dispatcher if it exists
*/
diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c
index fc051814b..aef1b7976 100644
--- a/src/lua/lua_util.c
+++ b/src/lua/lua_util.c
@@ -649,7 +649,7 @@ lua_util_process_message (lua_State *L)
if (cfg != NULL && message != NULL) {
base = event_init ();
rspamd_init_filters (cfg, FALSE, NULL);
- task = rspamd_task_new (NULL, cfg);
+ task = rspamd_task_new (NULL, cfg, NULL);
task->ev_base = base;
task->msg.begin = rspamd_mempool_alloc (task->task_pool, mlen);
rspamd_strlcpy ((gpointer)task->msg.begin, message, mlen);
diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c
index f5471eee4..b15efdfe9 100644
--- a/src/plugins/fuzzy_check.c
+++ b/src/plugins/fuzzy_check.c
@@ -2675,7 +2675,7 @@ fuzzy_process_handler (struct rspamd_http_connection_entry *conn_ent,
gint r, *saved, rules = 0, err_idx;
/* Prepare task */
- task = rspamd_task_new (session->wrk, session->cfg);
+ task = rspamd_task_new (session->wrk, session->cfg, NULL);
task->cfg = ctx->cfg;
task->ev_base = conn_ent->rt->ev_base;
saved = rspamd_mempool_alloc0 (session->pool, sizeof (gint));
diff --git a/src/rspamadm/lua_repl.c b/src/rspamadm/lua_repl.c
index d7d7721a8..7cf014fbe 100644
--- a/src/rspamadm/lua_repl.c
+++ b/src/rspamadm/lua_repl.c
@@ -358,7 +358,7 @@ rspamadm_lua_message_handler (lua_State *L, gint argc, gchar **argv)
rspamd_printf ("cannot open %s: %s\n", argv[i], strerror (errno));
}
else {
- task = rspamd_task_new (NULL, NULL);
+ task = rspamd_task_new (NULL, NULL, NULL);
if (!rspamd_task_load_message (task, NULL, map, len)) {
rspamd_printf ("cannot load %s\n", argv[i]);
diff --git a/src/rspamd_proxy.c b/src/rspamd_proxy.c
index 1b30827e7..c86f73f88 100644
--- a/src/rspamd_proxy.c
+++ b/src/rspamd_proxy.c
@@ -1596,7 +1596,7 @@ rspamd_proxy_self_scan (struct rspamd_proxy_session *session)
gsize len;
msg = session->client_message;
- task = rspamd_task_new (session->worker, session->ctx->cfg);
+ task = rspamd_task_new (session->worker, session->ctx->cfg, NULL);
task->flags |= RSPAMD_TASK_FLAG_MIME;
task->sock = -1;
diff --git a/src/worker.c b/src/worker.c
index 5bb4b2d61..80bf13d80 100644
--- a/src/worker.c
+++ b/src/worker.c
@@ -102,7 +102,7 @@ rspamd_worker_call_finish_handlers (struct rspamd_worker *worker)
if (cfg->finish_callbacks) {
ctx = worker->ctx;
/* Create a fake task object for async events */
- task = rspamd_task_new (worker, cfg);
+ task = rspamd_task_new (worker, cfg, NULL);
task->resolver = ctx->resolver;
task->ev_base = ctx->ev_base;
task->flags |= RSPAMD_TASK_FLAG_PROCESSING;
@@ -369,7 +369,7 @@ accept_socket (gint fd, short what, void *arg)
return;
}
- task = rspamd_task_new (worker, ctx->cfg);
+ task = rspamd_task_new (worker, ctx->cfg, NULL);
msg_info_task ("accepted connection from %s port %d, task ptr: %p",
rspamd_inet_address_to_string (addr),