MINOR: memprof: add one pointer size to the size of allocations

The current model causes an issue when trying to spot memory leaks,
because malloc(0) or realloc(0) do not count as allocations since we only
account for the application-usable size. This is the problem that made
issue #1406 not to appear as a leak.

What we're doing now is to account for one extra pointer (the one that
memory allocators usually place before the returned area), so that a
malloc(0) will properly account for 4 or 8 bytes. We don't need something
exact, we just need something non-zero so that a realloc(X) followed by a
realloc(0) without a free() gives a small non-zero result.

It was verified that the results are stable including in the presence
of lots of malloc/realloc/free as happens when stressing Lua.

It would make sense to backport this to 2.4 as it helps in bug reports.

(cherry picked from commit 1de51eb7279fb4257bdb3816c5e9a7990b7ae211)
Signed-off-by: Willy Tarreau <w@1wt.eu>
diff --git a/src/activity.c b/src/activity.c
index 4a7def1..d0c3747 100644
--- a/src/activity.c
+++ b/src/activity.c
@@ -239,7 +239,7 @@
 		return memprof_malloc_handler(size);
 
 	ret = memprof_malloc_handler(size);
-	size = malloc_usable_size(ret);
+	size = malloc_usable_size(ret) + sizeof(void *);
 
 	bin = memprof_get_bin(__builtin_return_address(0), MEMPROF_METH_MALLOC);
 	_HA_ATOMIC_ADD(&bin->alloc_calls, 1);
@@ -264,7 +264,7 @@
 		return memprof_calloc_handler(nmemb, size);
 
 	ret = memprof_calloc_handler(nmemb, size);
-	size = malloc_usable_size(ret);
+	size = malloc_usable_size(ret) + sizeof(void *);
 
 	bin = memprof_get_bin(__builtin_return_address(0), MEMPROF_METH_CALLOC);
 	_HA_ATOMIC_ADD(&bin->alloc_calls, 1);
@@ -295,6 +295,10 @@
 	ret = memprof_realloc_handler(ptr, size);
 	size = malloc_usable_size(ret);
 
+	/* only count the extra link for new allocations */
+	if (!ptr)
+		size += sizeof(void *);
+
 	bin = memprof_get_bin(__builtin_return_address(0), MEMPROF_METH_REALLOC);
 	if (size > size_before) {
 		_HA_ATOMIC_ADD(&bin->alloc_calls, 1);
@@ -327,7 +331,7 @@
 		return;
 	}
 
-	size_before = malloc_usable_size(ptr);
+	size_before = malloc_usable_size(ptr) + sizeof(void *);
 	memprof_free_handler(ptr);
 
 	bin = memprof_get_bin(__builtin_return_address(0), MEMPROF_METH_FREE);