-
Notifications
You must be signed in to change notification settings - Fork 209
Stats collection broken in tideways_realloc() #99
Description
tideways_realloc() does not correctly collect the allocation stats when wrapping the realloc() function.
It currently assumes that:
- a new allocation is always done, which is not true.
- a free (of the old memory) is always done, which is not true. Furthermore realloc can be called with NULL as first argument in order to perform an initial allocation.
- the total allocated memory is always incremented by the size given as 2nd argument, which is not true.
From the manpage man 3 realloc:
The realloc() function changes the size of the memory block pointed to by ptr to size bytes. The contents will be unchanged in the range from the start of the region up to the minimum of the
old and new sizes. If the new size is larger than the old size, the added memory will not be initialized. If ptr is NULL, then the call is equivalent to malloc(size), for all values of
size; if size is equal to zero, and ptr is not NULL, then the call is equivalent to free(ptr). Unless ptr is NULL, it must have been returned by an earlier call to malloc(), calloc(), or
realloc(). If the area pointed to was moved, a free(ptr) is done.