@@ -899,27 +899,25 @@ static void traverse_tree_submodules(struct repository *r,
{
struct tree_desc tree;
struct submodule_tree_entry *st_entry;
- struct name_entry *name_entry;
+ struct name_entry name_entry;
char *tree_path = NULL;
- name_entry = xmalloc(sizeof(*name_entry));
-
fill_tree_descriptor(r, &tree, treeish_name);
- while (tree_entry(&tree, name_entry)) {
+ while (tree_entry(&tree, &name_entry)) {
if (prefix)
tree_path =
- mkpathdup("%s/%s", prefix, name_entry->path);
+ mkpathdup("%s/%s", prefix, name_entry.path);
else
- tree_path = xstrdup(name_entry->path);
+ tree_path = xstrdup(name_entry.path);
- if (S_ISGITLINK(name_entry->mode) &&
+ if (S_ISGITLINK(name_entry.mode) &&
is_tree_submodule_active(r, root_tree, tree_path)) {
ALLOC_GROW(out->entries, out->entry_nr + 1,
out->entry_alloc);
st_entry = &out->entries[out->entry_nr++];
st_entry->name_entry = xmalloc(sizeof(*st_entry->name_entry));
- *st_entry->name_entry = *name_entry;
+ *st_entry->name_entry = name_entry;
st_entry->submodule =
submodule_from_path(r, root_tree, tree_path);
st_entry->repo = xmalloc(sizeof(*st_entry->repo));
@@ -927,9 +925,9 @@ static void traverse_tree_submodules(struct repository *r,
root_tree))
FREE_AND_NULL(st_entry->repo);
- } else if (S_ISDIR(name_entry->mode))
+ } else if (S_ISDIR(name_entry.mode))
traverse_tree_submodules(r, root_tree, tree_path,
- &name_entry->oid, out);
+ &name_entry.oid, out);
free(tree_path);
}
}
We traverse through submodules in the tree via `tree_entry()`, passing to it a `struct name_entry` that it is supposed to populate with the tree entry's contents. We unnecessarily allocate this variable instead of passing a variable that is allocated on the stack, and the ultimately don't even free that variable. This is unnecessary and leaks memory. Convert the variable to instead be allocated on the stack to plug the memory leak. Signed-off-by: Patrick Steinhardt <ps@pks.im> --- submodule-config.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)