]> git.ipfire.org Git - thirdparty/git.git/commit
parse-options: free previous value of `OPTION_FILENAME`
authorPatrick Steinhardt <ps@pks.im>
Thu, 26 Sep 2024 11:46:32 +0000 (13:46 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 27 Sep 2024 15:25:35 +0000 (08:25 -0700)
commitcf8c4237ebc653fdbc3285a38945f407d08245e5
treef2eeecbab3de258d3cc8c72581c1b5d2531260f8
parent76c7e708bbd6b19856d1ffa58f720e8da0c9eb0f
parse-options: free previous value of `OPTION_FILENAME`

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.

Refactor the function to always free the previous value. None of the
sites where this option is used pass a string constant, so this change
is safe.

While at it, fix the argument of `fix_filename()` to be a string
constant. The only reason why it's not is because we use it as an
in-out-parameter, where the input is a constant and the output is not.
This is weird and unnecessary, as we can just return the result instead
of using the parameter for this.

This leak is being hit in t7621, but plugging it alone does not make the
test suite pass.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
parse-options.c