From: Willy Tarreau Date: Tue, 3 Nov 2020 14:59:23 +0000 (+0100) Subject: MINOR: debug: don't count free(NULL) in memstats X-Git-Tag: v2.3.0~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9dd7f4fb4bf84450f0eb01b6e2d206f8481727fb;p=thirdparty%2Fhaproxy.git MINOR: debug: don't count free(NULL) in memstats The mem stats are pretty convenient to spot leaks, except that they count free(NULL) as 1, and the code does actually have quite a number of free(foo) guards where foo is NULL if the object was already freed. Let's just not count these ones so that the stats remain consistent. Now it's possible to compare the strdup()/malloc() and free() and verify they are consistent. --- diff --git a/include/haproxy/bug.h b/include/haproxy/bug.h index ad2018b138..f5ed7f419a 100644 --- a/include/haproxy/bug.h +++ b/include/haproxy/bug.h @@ -124,7 +124,8 @@ struct mem_stats { }; \ __asm__(".globl __start_mem_stats"); \ __asm__(".globl __stop_mem_stats"); \ - _HA_ATOMIC_ADD(&_.calls, 1); \ + if (__x) \ + _HA_ATOMIC_ADD(&_.calls, 1); \ free(__x); \ })