Commit 3865f7f6610563864d8f7a2671229b6fd398cd1b

Russell Belfer 2012-12-27T23:23:12

Invalid ref name normalization leaked memory When normalizing a reference name, if there is an error because the name is invalid, then the memory allocated for storing the name could be leaked if the caller was not careful and assumed that the error return code meant that no allocation had occurred. This fixes that by explicitly deallocating the reference name buffer if there is an error in normalizing the name.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
diff --git a/src/refs.c b/src/refs.c
index 35babaa..c77e9a5 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -1729,6 +1729,9 @@ cleanup:
 			GITERR_REFERENCE,
 			"The given reference name '%s' is not valid", name);
 
+	if (error && normalize)
+		git_buf_free(buf);
+
 	return error;
 }