This function changes the size of a dynamically allocated region
of memory, preserving its contents up to the minimum of the old
and new sizes. This may involve copying the contents to a new
location, so a new pointer is returned (and the old memory freed
if necessary).
This function is similar to the standard C "realloc" function
except that it provides better security against programming
errors and also supports the allocation of zero-size memory
regions (indicated by a NULL pointer).