From: Tobias Brunner Date: Wed, 15 Jun 2016 09:22:04 +0000 (+0200) Subject: leak-detective: Make sure to actually call malloc() from calloc() hook X-Git-Tag: 5.5.0dr1~18 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=e0c59faa68127b9016c45b3ff6ca6e93e19d6970;p=thirdparty%2Fstrongswan.git leak-detective: Make sure to actually call malloc() from calloc() hook Newer versions of GCC are too "smart" and replace a call to malloc(X) followed by a call to memset(0,X) with a call co calloc(), which obviously results in an infinite loop when it does that in our own calloc() implementation. Using `volatile` for the variable storing the total size prevents the optimization and we actually call malloc(). --- diff --git a/src/libstrongswan/utils/leak_detective.c b/src/libstrongswan/utils/leak_detective.c index 1543c7f999..a0bdae7155 100644 --- a/src/libstrongswan/utils/leak_detective.c +++ b/src/libstrongswan/utils/leak_detective.c @@ -810,10 +810,11 @@ HOOK(void*, malloc, size_t bytes) HOOK(void*, calloc, size_t nmemb, size_t size) { void *ptr; + volatile size_t total; - size *= nmemb; - ptr = malloc(size); - memset(ptr, 0, size); + total = nmemb * size; + ptr = malloc(total); + memset(ptr, 0, total); return ptr; }