DEBUG/MEDIUM: memory: optionally protect free data in pools

When debugging a core file, it's sometimes convenient to be able to
visit the released entries in the pools (typically last released
session). Unfortunately the first bytes of these entries are destroyed
by the link elements of the pool. And of course, most structures have
their most accessed elements at the beginning of the structure (typically
flags). Let's add a build-time option DEBUG_MEMORY_POOLS which allocates
an extra pointer in each pool to put the link at the end of each pool
item instead of the beginning.
diff --git a/src/memory.c b/src/memory.c
index d9cef64..0363f36 100644
--- a/src/memory.c
+++ b/src/memory.c
@@ -33,14 +33,16 @@
 	struct list *start;
 	unsigned int align;
 
-	/* We need to store at least a (void *) in the chunks. Since we know
+	/* We need to store a (void *) at the end of the chunks. Since we know
 	 * that the malloc() function will never return such a small size,
 	 * let's round the size up to something slightly bigger, in order to
 	 * ease merging of entries. Note that the rounding is a power of two.
+	 * This extra (void *) is not accounted for in the size computation
+	 * so that the visible parts outside are not affected.
 	 */
 
 	align = 16;
-	size  = (size + align - 1) & -align;
+	size  = ((size + POOL_EXTRA + align - 1) & -align) - POOL_EXTRA;
 
 	start = &pools;
 	pool = NULL;
@@ -99,7 +101,7 @@
 		if (pool->limit && pool->allocated >= pool->limit)
 			return NULL;
 
-		ptr = MALLOC(pool->size);
+		ptr = MALLOC(pool->size + POOL_EXTRA);
 		if (!ptr) {
 			if (failed)
 				return NULL;
@@ -110,7 +112,7 @@
 		if (++pool->allocated > avail)
 			break;
 
-		*(void **)ptr = (void *)pool->free_list;
+		*POOL_LINK(pool, ptr) = (void *)pool->free_list;
 		pool->free_list = ptr;
 	}
 	pool->used++;
@@ -129,7 +131,7 @@
 	next = pool->free_list;
 	while (next) {
 		temp = next;
-		next = *(void **)temp;
+		next = *POOL_LINK(pool, temp);
 		pool->allocated--;
 		FREE(temp);
 	}
@@ -158,7 +160,7 @@
 		while (next &&
 		       (int)(entry->allocated - entry->used) > (int)entry->minavail) {
 			temp = next;
-			next = *(void **)temp;
+			next = *POOL_LINK(entry, temp);
 			entry->allocated--;
 			FREE(temp);
 		}