Subject: Re: [PATCH 3/3] for-each-ref: introduce %(upstream:track[short])

From: Jonathan Nieder <[email-masked]>
Date: Fri, 27 Sep 2013 15:18:45 -0700

Johannes Sixt wrote:
> Am 9/27/2013 14:10, schrieb Ramkumar Ramachandra:

>> +					v->s = xstrdup(buf);
>> +				}
>
> These strdupped strings are leaked, right?

The convention seems to be that each refinfo owns its atom_value,
which owns its string that is kept on the heap.  Except when it isn't
(e.g., "v->s = typename(obj->type);").  So at least this patch doesn't
make the muddle any worse. ;-)

A nice followup would be to consistently allocate atom_value.s on the
heap, check for a GIT_FREE_AT_EXIT envvar, and free the refinfos
if that envvar is set at exit.  That would make sure that the code is
careful enough with memory to some day free some refinfo earlier when
there are many refs.  Until that's ready, I think continuing to mix
and match like this (constant strings left as is, dynamically
generated strings on the heap) is the best we can do.

Thanks,
Jonathan