Skip to content

Commit f8d2ca7

Browse files
pks-tgitster
authored andcommitted
submodule: fix leaking submodule ODB paths
In `add_submodule_odb_by_path()` we add a path into a global string list. The list is initialized with `NODUP`, which means that we do not pass ownership of strings to the list. But we use `xstrdup()` when we insert a path, with the consequence that the string will never get free'd. Plug the leak by marking the list as `DUP`. There is only a single callsite where we insert paths anyway, and as explained above that callsite was mishandling the allocation. This leak is exposed by t7814, but plugging it does not make the whole test suite pass. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 64d9ada commit f8d2ca7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

submodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,11 @@ void stage_updated_gitmodules(struct index_state *istate)
175175
die(_("staging updated .gitmodules failed"));
176176
}
177177

178-
static struct string_list added_submodule_odb_paths = STRING_LIST_INIT_NODUP;
178+
static struct string_list added_submodule_odb_paths = STRING_LIST_INIT_DUP;
179179

180180
void add_submodule_odb_by_path(const char *path)
181181
{
182-
string_list_insert(&added_submodule_odb_paths, xstrdup(path));
182+
string_list_insert(&added_submodule_odb_paths, path);
183183
}
184184

185185
int register_all_submodule_odb_as_alternates(void)

0 commit comments

Comments
 (0)