Commit 0b9c68b1 by Patrick Steinhardt

submodule: fix submodule names depending on config-owned memory

When populating the list of submodule names, we use the submodule
configuration entry's name as the key in the map of submodule names.
This creates a hidden dependency on the liveliness of the configuration
that was used to parse the submodule, which is fragile and unexpected.

Fix the issue by duplicating the string before writing it into the
submodule name map.
parent df33b43d
...@@ -199,13 +199,15 @@ out: ...@@ -199,13 +199,15 @@ out:
*/ */
static void free_submodule_names(git_strmap *names) static void free_submodule_names(git_strmap *names)
{ {
git_buf *name; const char *key;
char *value;
if (names == NULL) if (names == NULL)
return; return;
git_strmap_foreach_value(names, name, { git_strmap_foreach(names, key, value, {
git__free(name); git__free((char *) key);
git__free(value);
}); });
git_strmap_free(names); git_strmap_free(names);
...@@ -257,7 +259,7 @@ static int load_submodule_names(git_strmap **out, git_repository *repo, git_conf ...@@ -257,7 +259,7 @@ static int load_submodule_names(git_strmap **out, git_repository *repo, git_conf
if (!isvalid) if (!isvalid)
continue; continue;
git_strmap_insert(names, entry->value, git_buf_detach(&buf), &rval); git_strmap_insert(names, git__strdup(entry->value), git_buf_detach(&buf), &rval);
if (rval < 0) { if (rval < 0) {
giterr_set(GITERR_NOMEMORY, "error inserting submodule into hash table"); giterr_set(GITERR_NOMEMORY, "error inserting submodule into hash table");
error = -1; error = -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment