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