Subject: Re: [PATCH 12/23] parse-options: free previous value of `OPTION_FILENAME`

From: Junio C Hamano <[email-masked]>
Date: Fri, 20 Sep 2024 10:21:13 -0700

Patrick Steinhardt <[email-masked]> writes:

> The `OPTION_FILENAME` option always assigns either an allocated string
> or `NULL` to the value. In case it is passed multiple times it does not
> know to free the previous value though, which causes a memory leak.

Our earlier attitude was "the user gave --filename twice from the
command line, fully knowing that the last one wins rule will make
the earlier one have no effect; not worth worrying about".

But defining the memory ownership rules and make sure the
library-ish part of the codebase honors these rules is absolutely
the right thing to do.

We saw earlier that OPT_PASSTHRU correctly frees the original value
before assigning the new value, and this makes OPT_FILENAME do the
same thing.  Nice.