]> git.ipfire.org Git - thirdparty/git.git/commit
builtin/mv: fix leaks for submodule gitfile paths
authorPatrick Steinhardt <ps@pks.im>
Mon, 27 May 2024 11:47:23 +0000 (13:47 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 27 May 2024 18:20:03 +0000 (11:20 -0700)
commitebdbefa4fe9f618347124b37d44e517e0c6a3e4c
treec10f5591780372b3afb4641ccb8d9cb85d643a7a
parent52a7dab439e53d05adb9edc870c92a446e5a9143
builtin/mv: fix leaks for submodule gitfile paths

Similar to the preceding commit, we have effectively given tracking
memory ownership of submodule gitfile paths. Refactor the code to start
tracking allocated strings in a separate `struct strvec` such that we
can easily plug those leaks. Mark now-passing tests as leak free.

Note that ideally, we wouldn't require two separate data structures to
track those paths. But we do need to store `NULL` pointers for the
gitfile paths such that we can indicate that its corresponding entries
in the other arrays do not have such a path at all. And given that
`struct strvec`s cannot store `NULL` pointers we cannot use them to
store this information.

There is another small gotcha that is easy to miss: you may be wondering
why we don't want to store `SUBMODULE_WITH_GITDIR` in the strvec. This
is because this is a mere sentinel value and not actually a string at
all.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/mv.c
t/t4059-diff-submodule-not-initialized.sh
t/t7001-mv.sh
t/t7417-submodule-path-url.sh
t/t7421-submodule-summary-add.sh