Commit Diff


commit - 5514426792c3f9a07f4ab50620e8244650937c2d
commit + 349f6f393b11b80d99334e0f813be1e1c30ce209
blob - 1efdc66c190b41171847a26d4cad8f4ea30f7aa4
blob + 4d1d0e1751dc02091b79eed65be347563e71679b
--- gotwebd/got_operations.c
+++ gotwebd/got_operations.c
@@ -436,16 +436,6 @@ got_get_repo_commits(struct request *c, int limit)
 	for (;;) {
 		struct got_object_id *next_id;
 
-		if (limit_chk == ((limit * qs->page) - (limit - 1)) &&
-		    commit_found == 0 && repo_commit &&
-		    repo_commit->commit_id != NULL) {
-			t->prev_id = strdup(repo_commit->commit_id);
-			if (t->prev_id == NULL) {
-				error = got_error_from_errno("strdup");
-				goto done;
-			}
-		}
-
 		error = got_commit_graph_iter_next(&next_id, graph, repo, NULL,
 		    NULL);
 		if (error) {
@@ -467,12 +457,22 @@ got_get_repo_commits(struct request *c, int limit)
 		if (error)
 			goto done;
 
-		TAILQ_INSERT_TAIL(&t->repo_commits, repo_commit, entry);
-
 		error = got_get_repo_commit(c, repo_commit, commit,
 		    &refs, next_id);
-		if (error)
+		if (error) {
+			gotweb_free_repo_commit(repo_commit);
 			goto done;
+		}
+
+		if (limit_chk == ((limit * qs->page) - limit) &&
+		    commit_found == 0 && repo_commit->commit_id != NULL) {
+			t->prev_id = strdup(repo_commit->commit_id);
+			if (t->prev_id == NULL) {
+				error = got_error_from_errno("strdup");
+				gotweb_free_repo_commit(repo_commit);
+				goto done;
+			}
+		}
 
 		if (qs->commit != NULL && commit_found == 0 && limit != 1) {
 			if (strcmp(qs->commit, repo_commit->commit_id) == 0)
@@ -481,11 +481,14 @@ got_get_repo_commits(struct request *c, int limit)
 			    qs->page == 0)
 				commit_found = 1;
 			else {
+				gotweb_free_repo_commit(repo_commit);
 				limit_chk++;
 				continue;
 			}
 		}
 
+		TAILQ_INSERT_TAIL(&t->repo_commits, repo_commit, entry);
+
 		if (limit == 1 && chk_multi == 0 &&
 		    srv->max_commits_display != 1)
 			commit_found = 1;