Instead of freeing memory that's being replaced with new data, realloc it.