Why not use realloc here? A free + malloc seems unnecessary. Esp if the buffer may already be big enough.