aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2009-08-21 18:28:47 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2009-08-21 18:28:47 +0400
commit6e96678e839574fa246eacdffe328fadca783628 (patch)
tree2473fb08cfa28aee67e25a44317e0d666d68aed1 /src
parent6aa54cc5032b7bf089df667b567f304108cbd30c (diff)
downloadrspamd-6e96678e839574fa246eacdffe328fadca783628.tar.gz
rspamd-6e96678e839574fa246eacdffe328fadca783628.zip
* Fix processing of empty parts
* Fix memory problems in controller
Diffstat (limited to 'src')
-rw-r--r--src/filter.c4
-rw-r--r--src/message.c2
-rw-r--r--src/plugins/chartable.c4
-rw-r--r--src/plugins/fuzzy_check.c35
-rw-r--r--src/plugins/regexp.c13
5 files changed, 36 insertions, 22 deletions
diff --git a/src/filter.c b/src/filter.c
index 55c8b2a00..b75dd145f 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -517,6 +517,10 @@ statfiles_callback (gpointer key, gpointer value, void *arg)
if ((tokens = g_hash_table_lookup (data->tokens, st->tokenizer)) == NULL) {
while (cur != NULL) {
text_part = (struct mime_text_part *)cur->data;
+ if (text_part->is_empty) {
+ cur = g_list_next (cur);
+ continue;
+ }
c.begin = text_part->content->data;
c.len = text_part->content->len;
/* Tree would be freed at task pool freeing */
diff --git a/src/message.c b/src/message.c
index c4027ef14..e9d692a5d 100644
--- a/src/message.c
+++ b/src/message.c
@@ -517,6 +517,7 @@ process_text_part (struct worker_task *task, GByteArray *part_content, GMimeCont
text_part->is_empty = TRUE;
text_part->orig = NULL;
text_part->content = NULL;
+ task->text_parts = g_list_prepend (task->text_parts, text_part);
return;
}
text_part->orig = convert_text_to_utf (task, part_content, type, text_part);
@@ -553,6 +554,7 @@ process_text_part (struct worker_task *task, GByteArray *part_content, GMimeCont
text_part->is_empty = TRUE;
text_part->orig = NULL;
text_part->content = NULL;
+ task->text_parts = g_list_prepend (task->text_parts, text_part);
return;
}
text_part->orig = convert_text_to_utf (task, part_content, type, text_part);
diff --git a/src/plugins/chartable.c b/src/plugins/chartable.c
index 951285070..721dab452 100644
--- a/src/plugins/chartable.c
+++ b/src/plugins/chartable.c
@@ -194,11 +194,13 @@ static void
chartable_symbol_callback (struct worker_task *task, void *unused)
{
GList *cur;
+ struct mime_text_part *part;
if (check_view (task->cfg->views, chartable_module_ctx->symbol, task)) {
cur = g_list_first (task->text_parts);
while (cur) {
- if (check_part ((struct mime_text_part *)cur->data, task->cfg->raw_mode)) {
+ part = cur->data;
+ if (!part->is_empty && check_part (part, task->cfg->raw_mode)) {
insert_result (task, chartable_module_ctx->metric, chartable_module_ctx->symbol, 1, NULL);
}
cur = g_list_next (cur);
diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c
index ead1e2c83..da3e651a8 100644
--- a/src/plugins/fuzzy_check.c
+++ b/src/plugins/fuzzy_check.c
@@ -74,6 +74,7 @@ struct fuzzy_learn_session {
struct event ev;
fuzzy_hash_t *h;
int cmd;
+ int *saved;
struct timeval tv;
struct controller_session *session;
struct storage_server *server;
@@ -270,9 +271,6 @@ fuzzy_free_session (void *arg)
struct fuzzy_learn_session *session = arg;
event_del (&session->ev);
- if (session->task) {
- free_task (session->task, FALSE);
- }
}
static void
@@ -310,8 +308,8 @@ fuzzy_learn_callback (int fd, short what, void *arg)
session->server->port, errno, strerror (errno));
ok:
close (fd);
- session->task->save.saved --;
- if (session->task->save.saved == 0) {
+ (*session->saved) --;
+ if (*session->saved == 0) {
session->session->state = WRITE_REPLY;
r = snprintf (buf, sizeof (buf), "OK" CRLF);
rspamd_dispatcher_write (session->session->dispatcher, buf, r, FALSE, FALSE);
@@ -331,6 +329,10 @@ fuzzy_symbol_callback (struct worker_task *task, void *unused)
while (cur) {
part = cur->data;
+ if (part->is_empty) {
+ cur = g_list_next (cur);
+ continue;
+ }
selected = (struct storage_server *)get_upstream_by_hash (fuzzy_module_ctx->servers, fuzzy_module_ctx->servers_num,
sizeof (struct storage_server), task->ts.tv_sec,
DEFAULT_UPSTREAM_ERROR_TIME, DEFAULT_UPSTREAM_DEAD_TIME,
@@ -365,7 +367,7 @@ fuzzy_process_handler (struct controller_session *session, f_str_t *in)
struct mime_text_part *part;
struct storage_server *selected;
GList *cur;
- int sock, r, cmd = 0;
+ int sock, r, cmd = 0, *saved;
char out_buf[BUFSIZ];
if (session->other_data) {
@@ -377,12 +379,14 @@ fuzzy_process_handler (struct controller_session *session, f_str_t *in)
task->msg = in;
r = process_message (task);
+ saved = memory_pool_alloc0 (session->session_pool, sizeof (int));
if (r == -1) {
msg_warn ("read_socket: processing of message failed");
task->last_error = "MIME processing error";
task->error_code = RSPAMD_FILTER_ERROR;
free_task (task, FALSE);
session->state = WRITE_REPLY;
+ return;
}
else {
/* Plan new event for writing */
@@ -390,6 +394,10 @@ fuzzy_process_handler (struct controller_session *session, f_str_t *in)
while (cur) {
part = cur->data;
+ if (part->is_empty) {
+ cur = g_list_next (cur);
+ continue;
+ }
selected = (struct storage_server *)get_upstream_by_hash (fuzzy_module_ctx->servers, fuzzy_module_ctx->servers_num,
sizeof (struct storage_server), task->ts.tv_sec,
DEFAULT_UPSTREAM_ERROR_TIME, DEFAULT_UPSTREAM_DEAD_TIME,
@@ -398,6 +406,11 @@ fuzzy_process_handler (struct controller_session *session, f_str_t *in)
if (selected) {
if ((sock = make_tcp_socket (&selected->addr, selected->port, FALSE, TRUE)) == -1) {
msg_warn ("fuzzy_symbol_callback: cannot connect to %s, %d, %s", selected->name, errno, strerror (errno));
+ r = snprintf (out_buf, sizeof (out_buf), "no hashes written" CRLF);
+ rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE);
+ session->state = WRITE_REPLY;
+ free_task (task, FALSE);
+ return;
}
else {
s = memory_pool_alloc (session->session_pool, sizeof (struct fuzzy_learn_session));
@@ -405,13 +418,15 @@ fuzzy_process_handler (struct controller_session *session, f_str_t *in)
s->tv.tv_sec = IO_TIMEOUT;
s->tv.tv_usec = 0;
s->task = task;
- s->h = part->fuzzy;
+ s->h = memory_pool_alloc (session->session_pool, sizeof (fuzzy_hash_t));
+ memcpy (s->h, part->fuzzy, sizeof (fuzzy_hash_t));
s->session = session;
s->server = selected;
s->cmd = cmd;
+ s->saved = saved;
event_add (&s->ev, &s->tv);
memory_pool_add_destructor (session->session_pool, fuzzy_free_session, s);
- task->save.saved ++;
+ (*saved) ++;
}
}
else {
@@ -425,10 +440,10 @@ fuzzy_process_handler (struct controller_session *session, f_str_t *in)
}
}
- if (task->save.saved == 0) {
+ free_task (task, FALSE);
+ if (*saved == 0) {
r = snprintf (out_buf, sizeof (out_buf), "no hashes written" CRLF);
rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE);
- free_task (task, FALSE);
session->state = WRITE_REPLY;
}
}
diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c
index df5bba08a..dcbdce7b6 100644
--- a/src/plugins/regexp.c
+++ b/src/plugins/regexp.c
@@ -278,7 +278,7 @@ static gsize
process_regexp (struct rspamd_regexp *re, struct worker_task *task)
{
char *headerv, *c, t;
- struct mime_text_part *part, *tmp;
+ struct mime_text_part *part;
GList *cur, *headerlist;
GRegex *regexp;
struct url_regexp_param callback_param;
@@ -352,16 +352,7 @@ process_regexp (struct rspamd_regexp *re, struct worker_task *task)
task_cache_add (task, re, 1);
return 1;
}
- /* Skip identical parts */
- while (cur) {
- cur = g_list_next (cur);
- if (cur) {
- tmp = (struct mime_text_part *)cur->data;
- if (fuzzy_compare_hashes (tmp->fuzzy, part->fuzzy) > 70) {
- break;
- }
- }
- }
+ cur = g_list_next (cur);
}
task_cache_add (task, re, 0);
return 0;