--- libelwix/src/mem.c 2024/08/14 16:05:42 1.10 +++ libelwix/src/mem.c 2024/10/28 09:58:51 1.11 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: mem.c,v 1.10 2024/08/14 16:05:42 misho Exp $ +* $Id: mem.c,v 1.11 2024/10/28 09:58:51 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -91,7 +91,7 @@ mpool_init(u_long maxmem) void mpool_destroy(mpool_t ** __restrict mp) { - struct tagAlloc *m; + struct tagAlloc *m, *n; register int i; if (!mp || !*mp) @@ -100,14 +100,14 @@ mpool_destroy(mpool_t ** __restrict mp) mpool_lock(*mp); for (i = 0; i < MEM_BUCKETS; i++) { - while ((m = TAILQ_FIRST(&(*mp)->pool_active[i]))) { - TAILQ_REMOVE(&(*mp)->pool_active[i], m, alloc_node); + for (m = TAILQ_FIRST(&(*mp)->pool_active[i]); m; m = n) { + n = TAILQ_NEXT(m, alloc_node); if (m->alloc_mem) free(m->alloc_mem); free(m); } - while ((m = TAILQ_FIRST(&(*mp)->pool_inactive[i]))) { - TAILQ_REMOVE(&(*mp)->pool_inactive[i], m, alloc_node); + for (m = TAILQ_FIRST(&(*mp)->pool_inactive[i]); m; m = n) { + n = TAILQ_NEXT(m, alloc_node); if (m->alloc_mem) free(m->alloc_mem); free(m); @@ -318,7 +318,6 @@ mpool_realloc(mpool_t * __restrict mp, void * __restri memcpy(p, data, MIN(osize, newsize)); mpool_free(mp, data, 0); - data = p; } else { p = data;