]> git.ipfire.org Git - thirdparty/git.git/commit
builtin/rev-parse: fix memory leak with `--parseopt`
authorPatrick Steinhardt <ps@pks.im>
Thu, 1 Aug 2024 10:40:21 +0000 (12:40 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 1 Aug 2024 15:47:36 +0000 (08:47 -0700)
commit2d197e4a0f34b97b03416666bebcb993e41fed26
treed02e8d86af266c6c7e7fc33b7495379126f67a38
parent2e875b6cb408351c07919efb024ee1b52e0a3ac3
builtin/rev-parse: fix memory leak with `--parseopt`

The `--parseopt` mode allows shell scripts to have the same option
parsing mode as we have in C builtins. It soaks up a set of option
descriptions via stdin and massages them into proper `struct option`s
that we can then use to parse a set of arguments.

We only partially free those options when done though, creating a memory
leak. Interestingly, we only end up free'ing the first option's help,
which is of course wrong.

Fix this by freeing all option's help fields as well as their `argh`
fields to plug this memory leak.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/rev-parse.c
t/t1502-rev-parse-parseopt.sh