]> git.ipfire.org Git - thirdparty/git.git/commit
builtin/describe: fix memory leak with `--contains=`
authorPatrick Steinhardt <ps@pks.im>
Thu, 1 Aug 2024 10:38:20 +0000 (12:38 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 1 Aug 2024 15:47:35 +0000 (08:47 -0700)
commit8e2e28799d2353e32c393bd7938c457e5e08fc63
tree1aa91ad6229973707d392e5a0fec522e66cfd026
parent7935a026130f7dd430539685de0742dabb8e6047
builtin/describe: fix memory leak with `--contains=`

When calling `git describe --contains=`, we end up invoking
`cmd_name_rev()` with some munged argv array. This array may contain
allocated strings and furthermore will likely be modified by the called
function. This results in two memory leaks:

  - First, we leak the array that we use to assemble the arguments.

  - Second, we leak the allocated strings that we may have put into the
    array.

Fix those leaks by creating a separate copy of the array that we can
hand over to `cmd_name_rev()`. This allows us to free all strings
contained in the `strvec`, as the original vector will not be modified
anymore.

Furthermore, free both the `strvec` and the copied array to fix the
first memory leak.

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