mirror of
https://github.com/strongswan/strongswan.git
synced 2025-10-09 00:00:53 -04:00
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:
parent
8f1806605d
commit
e0c59faa68
@ -810,10 +810,11 @@ HOOK(void*, malloc, size_t bytes)
|
|||||||
HOOK(void*, calloc, size_t nmemb, size_t size)
|
HOOK(void*, calloc, size_t nmemb, size_t size)
|
||||||
{
|
{
|
||||||
void *ptr;
|
void *ptr;
|
||||||
|
volatile size_t total;
|
||||||
|
|
||||||
size *= nmemb;
|
total = nmemb * size;
|
||||||
ptr = malloc(size);
|
ptr = malloc(total);
|
||||||
memset(ptr, 0, size);
|
memset(ptr, 0, total);
|
||||||
|
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user