Commit 409305081372c7e881dfa8f35a2696366abc712b

panda 2021-02-18T16:36:42

index: Initialize case_sorted to GIT_VECTOR_INIT This is for extra safety within write_entries

diff --git a/src/index.c b/src/index.c
index 263f8e5..3d46030 100644
--- a/src/index.c
+++ b/src/index.c
@@ -2861,7 +2861,7 @@ static int write_entries(git_index *index, git_filebuf *file)
 {
 	int error = 0;
 	size_t i;
-	git_vector case_sorted, *entries;
+	git_vector case_sorted = GIT_VECTOR_INIT, *entries = NULL;
 	git_index_entry *entry;
 	const char *last = NULL;
 
@@ -2869,7 +2869,7 @@ static int write_entries(git_index *index, git_filebuf *file)
 	 * to re-sort it case-sensitively before writing */
 	if (index->ignore_case) {
 		if ((error = git_vector_dup(&case_sorted, &index->entries, git_index_entry_cmp)) < 0)
-			return error;
+			goto done;
 
 		git_vector_sort(&case_sorted);
 		entries = &case_sorted;
@@ -2887,9 +2887,8 @@ static int write_entries(git_index *index, git_filebuf *file)
 			last = entry->path;
 	}
 
-	if (index->ignore_case)
-		git_vector_free(&case_sorted);
-
+done:
+	git_vector_free(&case_sorted);
 	return error;
 }