diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-11-28 16:23:21 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-11-28 16:23:21 +0300 |
commit | 287067006bf2b44b9a68f3dd9d24414f4902e225 (patch) | |
tree | a6a162bda65c7c094a4432062516917af6ae2682 /src | |
parent | 8cff136c17d945280161d7f5224dc09341035bd9 (diff) | |
download | rspamd-287067006bf2b44b9a68f3dd9d24414f4902e225.tar.gz rspamd-287067006bf2b44b9a68f3dd9d24414f4902e225.zip |
Fix race condition.
Diffstat (limited to 'src')
-rw-r--r-- | src/kvstorage_file.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/kvstorage_file.c b/src/kvstorage_file.c index e15b22daf..fe401a268 100644 --- a/src/kvstorage_file.c +++ b/src/kvstorage_file.c @@ -198,6 +198,7 @@ file_process_queue (struct rspamd_kv_backend *backend) g_slice_free1 (len * sizeof (gint), fds); /* Clean the queue */ + g_hash_table_remove_all (db->ops_hash); cur = db->ops_queue->head; while (cur) { op = cur->data; @@ -214,7 +215,6 @@ file_process_queue (struct rspamd_kv_backend *backend) cur = g_list_next (cur); } - g_hash_table_remove_all (db->ops_hash); g_queue_clear (db->ops_queue); return TRUE; @@ -304,10 +304,13 @@ rspamd_file_insert (struct rspamd_kv_backend *backend, gpointer key, guint keyle /* We found another op with such key in this queue */ if (op->op == FILE_OP_DELETE || (op->elt->flags & KV_ELT_NEED_FREE) != 0) { /* Also clean memory */ + g_hash_table_steal (db->ops_hash, &search_elt); g_slice_free1 (ELT_SIZE (op->elt), op->elt); } op->op = FILE_OP_INSERT; op->elt = elt; + elt->flags |= KV_ELT_DIRTY; + g_hash_table_insert (db->ops_hash, elt, op); } else { op = g_slice_alloc (sizeof (struct file_op)); @@ -343,10 +346,13 @@ rspamd_file_replace (struct rspamd_kv_backend *backend, gpointer key, guint keyl /* We found another op with such key in this queue */ if (op->op == FILE_OP_DELETE || (op->elt->flags & KV_ELT_NEED_FREE) != 0) { /* Also clean memory */ + g_hash_table_steal (db->ops_hash, &search_elt); g_slice_free1 (ELT_SIZE (op->elt), op->elt); } op->op = FILE_OP_REPLACE; op->elt = elt; + elt->flags |= KV_ELT_DIRTY; + g_hash_table_insert (db->ops_hash, elt, op); } else { op = g_slice_alloc (sizeof (struct file_op)); |