submodule: plug leaks from the escape detection
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
diff --git a/src/submodule.c b/src/submodule.c
index 2b1b993..32e199c 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -186,10 +186,13 @@ static int load_submodule_names(git_strmap *out, git_repository *repo, git_confi
fdot = strchr(entry->name, '.');
ldot = strrchr(entry->name, '.');
+ git_buf_clear(&buf);
git_buf_put(&buf, fdot + 1, ldot - fdot - 1);
isvalid = git_submodule_name_is_valid(repo, buf.ptr, 0);
- if (isvalid < 0)
- return isvalid;
+ if (isvalid < 0) {
+ error = isvalid;
+ goto out;
+ }
if (!isvalid)
continue;
@@ -199,9 +202,13 @@ static int load_submodule_names(git_strmap *out, git_repository *repo, git_confi
return -1;
}
}
+ if (error == GIT_ITEROVER)
+ error = 0;
+out:
+ git_buf_free(&buf);
git_config_iterator_free(iter);
- return 0;
+ return error;
}
int git_submodule_lookup(
diff --git a/tests/submodule/escape.c b/tests/submodule/escape.c
index 0a3c4a3..f5c3cd4 100644
--- a/tests/submodule/escape.c
+++ b/tests/submodule/escape.c
@@ -43,6 +43,7 @@ void test_submodule_escape__from_gitdir(void)
"[submodule \"" EVIL_SM_NAME "\"]\n"
" path = testrepo\n"
" url = ../testrepo.git\n");
+ git_buf_free(&buf);
/* Find it all the different ways we know about it */
foundit = 0;
@@ -76,6 +77,7 @@ void test_submodule_escape__from_gitdir_windows(void)
"[submodule \"" EVIL_SM_NAME_WINDOWS "\"]\n"
" path = testrepo\n"
" url = ../testrepo.git\n");
+ git_buf_free(&buf);
/* Find it all the different ways we know about it */
foundit = 0;