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().
This commit is contained in:
Tobias Brunner 2016-06-15 11:22:04 +02:00
parent 8f1806605d
commit e0c59faa68

View File

@ -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;
}