From: Vladimír Čunát Date: Wed, 19 Sep 2018 17:39:26 +0000 (+0200) Subject: worker: safer code around the mempool freelist X-Git-Tag: v3.1.0~10^2~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b350d38d;p=thirdparty%2Fknot-resolver.git worker: safer code around the mempool freelist I did NOT remove this one, as in a quick profile that would be increase in roughly 0.5% time in malloc, so that's possibly justifiable. (And this one is much less obstructing to splitting the worker code.) --- diff --git a/daemon/worker.c b/daemon/worker.c index 90004649b..b6eb5939f 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -1797,17 +1797,19 @@ static int worker_reserve(struct worker_ctx *worker, size_t ring_maxlen) return kr_ok(); } -#define reclaim_freelist(list, type, cb) \ - for (unsigned i = 0; i < list.len; ++i) { \ - void *elm = list.at[i]; \ - kr_asan_unpoison(elm, sizeof(type)); \ - cb(elm); \ - } \ - array_clear(list) +static inline void reclaim_mp_freelist(mp_freelist_t *list) +{ + for (unsigned i = 0; i < list->len; ++i) { + struct mempool *e = list->at[i]; + kr_asan_unpoison(e, sizeof(*e)); + mp_delete(e); + } + array_clear(*list); +} void worker_reclaim(struct worker_ctx *worker) { - reclaim_freelist(worker->pool_mp, struct mempool, mp_delete); + reclaim_mp_freelist(&worker->pool_mp); mp_delete(worker->pkt_pool.ctx); worker->pkt_pool.ctx = NULL; trie_free(worker->subreq_out); diff --git a/daemon/worker.h b/daemon/worker.h index 5814a4bd3..dd9847672 100644 --- a/daemon/worker.h +++ b/daemon/worker.h @@ -109,7 +109,7 @@ void worker_request_set_source_session(struct request_ctx *, struct session *ses #define MAX_TCP_INACTIVITY (KR_RESOLVE_TIME_LIMIT + KR_CONN_RTT_MAX) /** Freelist of available mempools. */ -typedef array_t(void *) mp_freelist_t; +typedef array_t(struct mempool *) mp_freelist_t; /** List of query resolution tasks. */ typedef array_t(struct qr_task *) qr_tasklist_t;