Re: [PATCH 12/23] parse-options: free previous value of `OPTION_FILENAME`
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 20, 2024, 17:21 UTC
- Message-ID
- <xmqqy13m2qd2.fsf@gitster.g>
- In-Reply-To
- <330b6c52a0a99ba8fa18378310250e5b617d40c2.1726484308.git.ps@pks.im>
Patrick Steinhardt <ps@pks.im> 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.