Commit 899ec41fa18a13db50ae3c3fd1c4bb4045364e6d

Evan Hanson 2013-08-15T16:25:48

revparse: Free left side of invalid range revspecs This fixes a small memory leak in git_revparse where early returns on errors from git_revparse_single cause a free() on the (reallocated) left side of the revspec to be skipped.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
diff --git a/src/revparse.c b/src/revparse.c
index d21f08b..2fdad00 100644
--- a/src/revparse.c
+++ b/src/revparse.c
@@ -912,13 +912,9 @@ int git_revparse(
 			rstr++;
 		}
 
-		if ((error = git_revparse_single(&revspec->from, repo, lstr)) < 0) {
-			return error;
-		}
-
-		if ((error = git_revparse_single(&revspec->to, repo, rstr)) < 0) {
-			return error;
-		}
+		error = git_revparse_single(&revspec->from, repo, lstr);
+		if (error == 0)
+			error = git_revparse_single(&revspec->to, repo, rstr);
 
 		git__free((void*)lstr);
 	} else {