Replace realloc with free+malloc, the previous content of the buffer is