Correctly handle variadic arguments.

Also, no need to free buffer when using realloc.