On Fri, Jun 19, 2015 at 5:10 AM, Junio C Hamano <gits...@pobox.com> wrote:
> Paul Tan <pyoka...@gmail.com> writes:
>
>> +     /* commit message and metadata */
>> +     struct strbuf author_name;
>> +     struct strbuf author_email;
>> +     struct strbuf author_date;
>> +     struct strbuf msg;
>
> Same comment as "dir" in the earlier patch applies to these.  If the
> fields are read or computed and then kept constant, use a temporary
> variable that is a strbuf to read/compute the final value, and then
> detach to a "const char *" field.  If they are constantly changing
> and in-place updates are vital, then they can and should be strbufs,
> but I do not think that is the case for these.

I do think it is the case here. The commit message and metadata fields
change for every patch we process, and we could be processing a large
volume of patches, so we must be careful to not leak any memory.

We could use a char* field, but then to prevent memory leaks we would
then have to free() it and malloc() a new string for every patch we
process, which will lead to lots of malloc()s and free()s over a large
volume of patches that can lead to memory fragmentation.

Regards,
Paul
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to