Commit cfed1be8949ed441485c6686f1dbc022d03de192

Carlos Martín Nieto 2018-05-24T20:28:36

submodule: plug leaks from the escape detection

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;