auto *real_dyn_item = C_API_SYMCACHE_DYN_ITEM(item);
cache_runtime->finalize_item(task, real_dyn_item);
+}
+
+void
+rspamd_symcache_runtime_destroy (struct rspamd_task *task)
+{
+ auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime);
+ cache_runtime->savepoint_dtor();
}
\ No newline at end of file
sizeof(struct cache_dynamic_item) * cur_order->size());
checkpoint->order = cache.get_cache_order();
- rspamd_mempool_add_destructor(task->task_pool,
- symcache_runtime::savepoint_dtor, checkpoint);
/* Calculate profile probability */
ev_now_update_if_cheap(task->event_loop);
{
auto *cbd = (struct rspamd_symcache_delayed_cbdata *) ud;
+ cbd->event = nullptr;
cbd->runtime->unset_slow();
ev_timer_stop(cbd->task->event_loop, &cbd->tm);
}
{
auto *cbd = (struct rspamd_symcache_delayed_cbdata *) w->data;
- cbd->event = NULL;
+ if (cbd->event) {
+ cbd->event = nullptr;
- /* Timer will be stopped here */
- rspamd_session_remove_event (cbd->task->s,
- rspamd_symcache_delayed_item_fin, cbd);
- cbd->runtime->process_item_rdeps(cbd->task, cbd->item);
+ /* Timer will be stopped here */
+ rspamd_session_remove_event (cbd->task->s,
+ rspamd_symcache_delayed_item_fin, cbd);
+
+ cbd->runtime->process_item_rdeps(cbd->task, cbd->item);
+ }
}
auto *cbd = (struct rspamd_symcache_delayed_cbdata *) d;
if (cbd->event) {
- /* Event has not been executed */
+ /* Event has not been executed, this will also stop a timer */
rspamd_session_remove_event (cbd->task->s,
rspamd_symcache_delayed_item_fin, cbd);
cbd->event = nullptr;
{
auto *cache_ptr = reinterpret_cast<symcache *>(task->cfg->cache);
+ // Avoid race condition with the runtime destruction and the delay timer
+ if (!order) {
+ return;
+ }
+
for (const auto &rdep: item->rdeps) {
if (rdep.item) {
auto *dyn_item = get_dynamic_item(rdep.item->id);
mutable struct cache_dynamic_item dynamic_items[];
/* We allocate this structure merely in memory pool, so destructor is absent */
~symcache_runtime() = delete;
- /* Dropper for a shared ownership */
- static auto savepoint_dtor(void *ptr) -> void {
- auto *real_savepoint = (symcache_runtime *)ptr;
-
- /* Drop shared ownership */
- real_savepoint->order.reset();
- }
auto process_symbol(struct rspamd_task *task, symcache &cache, cache_item *item,
cache_dynamic_item *dyn_item) -> bool;
cache_dynamic_item *dyn_item, bool check_only) -> bool;
public:
+ /* Dropper for a shared ownership */
+ auto savepoint_dtor() -> void {
+
+ /* Drop shared ownership */
+ order.reset();
+ }
/**
* Creates a cache runtime using task mempool
* @param task
rspamd_message_unref (task->message);
if (task->flags & RSPAMD_TASK_FLAG_OWN_POOL) {
+ rspamd_mempool_destructors_enforce (task->task_pool);
+
+ if (task->symcache_runtime) {
+ rspamd_symcache_runtime_destroy (task);
+ }
+
rspamd_mempool_delete (task->task_pool);
}
+ else if (task->symcache_runtime) {
+ rspamd_symcache_runtime_destroy (task);
+ }
}
}