summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2011-08-05 14:52:21 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2011-08-05 14:52:21 +0400
commitf5867bfec49caebbe06b3058fd905dd243f07438 (patch)
treed56cc45d24b733e30672b1c556d628d2c481601b
parent6c4d8488b1322b6e53bc1f0beac94b790b34c5ae (diff)
downloadrspamd-f5867bfec49caebbe06b3058fd905dd243f07438.tar.gz
rspamd-f5867bfec49caebbe06b3058fd905dd243f07438.zip
Make hash traversing more safe by using reference count.
Update to 0.4.2
-rw-r--r--CMakeLists.txt2
-rw-r--r--src/filter.c4
-rw-r--r--src/protocol.c8
3 files changed, 11 insertions, 3 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 09ca24275..3ed111e59 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -7,7 +7,7 @@ PROJECT(rspamd C)
SET(RSPAMD_VERSION_MAJOR 0)
SET(RSPAMD_VERSION_MINOR 4)
-SET(RSPAMD_VERSION_PATCH 1)
+SET(RSPAMD_VERSION_PATCH 2)
SET(RSPAMD_VERSION "${RSPAMD_VERSION_MAJOR}.${RSPAMD_VERSION_MINOR}.${RSPAMD_VERSION_PATCH}")
diff --git a/src/filter.c b/src/filter.c
index 17dc6aa60..c0c21681d 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -64,7 +64,7 @@ insert_metric_result (struct worker_task *task, struct metric *metric, const gch
metric_res = memory_pool_alloc (task->task_pool, sizeof (struct metric_result));
metric_res->symbols = g_hash_table_new (g_str_hash, g_str_equal);
metric_res->checked = FALSE;
- memory_pool_add_destructor (task->task_pool, (pool_destruct_func) g_hash_table_destroy, metric_res->symbols);
+ memory_pool_add_destructor (task->task_pool, (pool_destruct_func) g_hash_table_unref, metric_res->symbols);
metric_res->metric = metric;
metric_res->grow_factor = 0;
metric_res->score = 0;
@@ -663,7 +663,7 @@ process_statfiles (struct worker_task *task)
if (task->tokens == NULL) {
task->tokens = g_hash_table_new (g_direct_hash, g_direct_equal);
- memory_pool_add_destructor (task->task_pool, (pool_destruct_func)g_hash_table_destroy, task->tokens);
+ memory_pool_add_destructor (task->task_pool, (pool_destruct_func)g_hash_table_unref, task->tokens);
}
g_list_foreach (task->cfg->classifiers, classifiers_callback, task);
diff --git a/src/protocol.c b/src/protocol.c
index a037e2b01..5c85a4a7d 100644
--- a/src/protocol.c
+++ b/src/protocol.c
@@ -829,7 +829,9 @@ show_metric_symbols_rspamc (struct metric_result *metric_res, struct metric_call
{
cd->cur_metric = metric_res->metric;
if (cd->alive) {
+ g_hash_table_ref (metric_res->symbols);
g_hash_table_foreach (metric_res->symbols, metric_symbols_callback_rspamc, cd);
+ g_hash_table_unref (metric_res->symbols);
/* Remove last , from log buf */
if (cd->log_buf[cd->log_offset - 1] == ',') {
cd->log_buf[--cd->log_offset] = '\0';
@@ -899,7 +901,9 @@ show_metric_symbols_json (struct metric_result *metric_res, struct metric_callba
" \"symbols\": [");
/* Print all symbols */
+ g_hash_table_ref (metric_res->symbols);
g_hash_table_foreach (metric_res->symbols, metric_symbols_callback_json, cd);
+ g_hash_table_unref (metric_res->symbols);
/* Remove last ',' symbol */
if (cd->symbols_buf[cd->symbols_offset - 1] == ',') {
cd->symbols_buf[--cd->symbols_offset] = '\0';
@@ -1314,7 +1318,9 @@ write_check_reply (struct worker_task *task)
g_hash_table_remove (task->results, "default");
/* Write result for each metric separately */
+ g_hash_table_ref (task->results);
g_hash_table_foreach (task->results, show_metric_result, &cd);
+ g_hash_table_unref (task->results);
if (!cd.alive) {
return FALSE;
}
@@ -1468,7 +1474,9 @@ write_process_reply (struct worker_task *task)
g_hash_table_remove (task->results, "default");
/* Write result for each metric separately */
+ g_hash_table_ref (task->results);
g_hash_table_foreach (task->results, show_metric_result, &cd);
+ g_hash_table_unref (task->results);
if (! cd.alive) {
return FALSE;
}