submodule--helper: free some "displaypath" in "struct update_data"

Make the update_data_release() function free "displaypath" member when appropriate. The "displaypath" member is always ours, the "const" on the "char *" was wrong to begin with. This leaves a leak of "displaypath" in update_submodule(), which as we'll see in subsequent commits is harder to deal with than this trivial fix. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Reviewed-by: Glen Choo <chooglen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Sep 1, 2022 at 01:14 UTC d40c42e06b1bbeab66b6911b864f57407ad68f95
4 files changed +5 -1
builtin/submodule--helper.c
+2 -1
@@ -1877,7 +1877,7 @@ static void submodule_update_clone_release(struct submodule_update_clone *suc)
1877
1878 struct update_data {
1879 const char *prefix;
1880 - const char *displaypath;
1880 + char *displaypath;
1881 enum submodule_update_type update_default;
1882 struct object_id suboid;
1883 struct string_list references;
@@ -1915,6 +1915,7 @@ struct update_data {
1915
1916 static void update_data_release(struct update_data *ud)
1917 {
1918 + free(ud->displaypath);
1919 module_list_release(&ud->list);
1920 }
1921
t/t2403-worktree-move.sh
+1
@@ -2,6 +2,7 @@
2
3 test_description='test git worktree move, remove, lock and unlock'
4
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 test_expect_success 'setup' '
t/t7412-submodule-absorbgitdirs.sh
+1
@@ -6,6 +6,7 @@ This test verifies that `git submodue absorbgitdirs` moves a submodules git
6 directory into the superproject.
7 '
8
9 +TEST_PASSES_SANITIZE_LEAK=true
10 . ./test-lib.sh
11
12 test_expect_success 'setup a real submodule' '
t/t7419-submodule-set-branch.sh
+1
@@ -9,6 +9,7 @@ This test verifies that the set-branch subcommand of git-submodule is working
9 as expected.
10 '
11
12 +TEST_PASSES_SANITIZE_LEAK=true
13 TEST_NO_CREATE_REPO=1
14 . ./test-lib.sh
15