]> git.ipfire.org Git - thirdparty/git.git/commit - bisect.c
revisions API: don't leak memory on argv elements that need free()-ing
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Tue, 2 Aug 2022 15:33:16 +0000 (17:33 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 3 Aug 2022 18:12:36 +0000 (11:12 -0700)
commitf92dbdbc6a8aa5f3979f4bb7a7b9bbc8ec9b4aa6
tree3979a3f381b683906af43e422fefd5523dd88257
parent57efebb9b96847adcd25bab0d2c21c599b8f1954
revisions API: don't leak memory on argv elements that need free()-ing

Add a "free_removed_argv_elements" member to "struct
setup_revision_opt", and use it to fix several memory leaks.

We have various memory leaks in APIs that take and munge "const
char **argv", e.g. parse_options(). Sometimes these APIs are given the
"argv" we get to the "main" function, in which case we don't leak
memory, but other times we're giving it the "v" member of a "struct
strvec" we created.

There's several potential ways to fix those sort of leaks, we could
add a "nodup" mode to "struct strvec", which would work for the cases
where we push constant strings to it. But that wouldn't work as soon
as we used strvec_pushf(), or otherwise needed to duplicate or create
a string for that "struct strvec".

Let's instead make it the responsibility of the revisions API. If it's
going to clobber elements of argv it can also free() them, which it
will now do if instructed to do so via "free_removed_argv_elements".

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
bisect.c
builtin/submodule--helper.c
remote.c
revision.c
revision.h
t/t2020-checkout-detach.sh