]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: memprof: properly account for differences for realloc()
authorWilly Tarreau <w@1wt.eu>
Tue, 11 May 2021 07:12:56 +0000 (09:12 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 11 May 2021 07:12:56 +0000 (09:12 +0200)
The realloc() function checks if the size grew or reduced in order to
count an allocation or a free, but it does so with the absolute (new
or old) value instead of the difference, resulting in realloc() often
being credited for allocating too much.

No backport is needed.

src/activity.c

index 4dc832ef6a4895036d7c8da7af4699d024ef2b5c..7d2ddace823d6122573f4108958be697d59dd8bc 100644 (file)
@@ -281,10 +281,10 @@ void *realloc(void *ptr, size_t size)
        bin = memprof_get_bin(__builtin_return_address(0));
        if (size > size_before) {
                _HA_ATOMIC_ADD(&bin->alloc_calls, 1);
-               _HA_ATOMIC_ADD(&bin->alloc_tot, size);
+               _HA_ATOMIC_ADD(&bin->alloc_tot, size - size_before);
        } else if (size < size_before) {
                _HA_ATOMIC_ADD(&bin->free_calls, 1);
-               _HA_ATOMIC_ADD(&bin->free_tot, size_before);
+               _HA_ATOMIC_ADD(&bin->free_tot, size_before - size);
        }
        return ret;
 }