# Re: \[PATCH v2 4/7\] var: adjust memory allocation for strings

- From: Junio C Hamano \<hidden\>
- Date: 2023-06-26 19:56:36 
- List: git
- Page: https://ratatoskr.run/git/2023/06/7971885
- Thread: https://ratatoskr.run/git/2023/06/7971885/t.md

```text
"brian m. carlson" [ref] writes:

> From: "brian m. carlson" <redacted>
>
> Right now, all of our values are constants whose allocation is managed
> elsewhere.  However, in the future, we'll have some variables whose
> memory we will need to free.  To keep things consistent, let's make each
> of our functions allocate its own memory and make the caller responsible
> for freeing it.
>
> Signed-off-by: brian m. carlson <redacted>
> ---
>  builtin/var.c | 45 +++++++++++++++++++++++++++++----------------
>  1 file changed, 29 insertions(+), 16 deletions(-)

Making everybody allocate like this patch does is also fine, but
FWIW, with [3/7], we can selectively set ".need_free = 1" for
minority of elements in the array that returns an allocated piece of
memory without making the source code too noisy (as the array
elements for existing majority can omit ".need_free = 0" and leave
it to the default initialization), so I am not opposed to the "we
set .need_free bit only for those that we allocate" approach taken
with the previous round.

Thanks.
```
