From 86900d40b0729c6d3467716e9150556e57be3442 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 17 Jan 2015 16:57:46 +0000 Subject: [PATCH] Revert "Preserve destructors order as LIFO." That change was completely incorrect. This reverts commit 1f2c83f096f28ce79e828edd1ab545a341f10451. --- src/libutil/mem_pool.c | 13 ++++++++----- src/libutil/mem_pool.h | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/libutil/mem_pool.c b/src/libutil/mem_pool.c index a292c082a..6c9ee6f16 100644 --- a/src/libutil/mem_pool.c +++ b/src/libutil/mem_pool.c @@ -27,7 +27,6 @@ #include "fstring.h" #include "logger.h" #include "util.h" -#include "utlist.h" #include "main.h" /* Sleep time for spin lock in nanoseconds */ @@ -541,7 +540,8 @@ rspamd_mempool_add_destructor_full (rspamd_mempool_t * pool, cur->data = data; cur->function = function; cur->loc = line; - DL_APPEND (pool->destructors, cur); + cur->prev = pool->destructors; + pool->destructors = cur; POOL_MTX_UNLOCK (); } } @@ -554,12 +554,14 @@ rspamd_mempool_replace_destructor (rspamd_mempool_t * pool, { struct _pool_destructors *tmp; - DL_FOREACH (pool->destructors, tmp) { + tmp = pool->destructors; + while (tmp) { if (tmp->func == func && tmp->data == old_data) { tmp->func = func; tmp->data = new_data; break; } + tmp = tmp->prev; } } @@ -569,15 +571,16 @@ rspamd_mempool_delete (rspamd_mempool_t * pool) { struct _pool_chain *cur = pool->first_pool, *tmp; struct _pool_chain_shared *cur_shared = pool->shared_pool, *tmp_shared; - struct _pool_destructors *destructor; + struct _pool_destructors *destructor = pool->destructors; POOL_MTX_LOCK (); /* Call all pool destructors */ - DL_FOREACH (pool->destructors, destructor) { + while (destructor) { /* Avoid calling destructors for NULL pointers */ if (destructor->data != NULL) { destructor->func (destructor->data); } + destructor = destructor->prev; } while (cur) { diff --git a/src/libutil/mem_pool.h b/src/libutil/mem_pool.h index 4552e8ca3..7403ced29 100644 --- a/src/libutil/mem_pool.h +++ b/src/libutil/mem_pool.h @@ -78,7 +78,7 @@ struct _pool_destructors { void *data; /**< data to free */ const gchar *function; /**< function from which this destructor was added */ const gchar *loc; /**< line number */ - struct _pool_destructors *prev, *next; /**< chain link */ + struct _pool_destructors *prev; /**< chain link */ }; /** -- 2.39.5