commit 349f6f393b11b80d99334e0f813be1e1c30ce209 from: Omar Polo via: Thomas Adam date: Wed Sep 07 14:32:00 2022 UTC gotwebd: fix briefs navigation broken in 4a9629420 got_get_repo_commits iterates over the commits and build a queue for later display. My previous memleak fix moved the TAILQ_INSERT_TAIL *before* the logic to exit the loop and so it broke the pagination. This fixes it by delaying the insertion into the queue, but also by moving the check for the "previous" button after we've opened the commit. ok tracey 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;