clean up commit list in print_commits() after any error in the loop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
diff --git a/got/got.c b/got/got.c
index 598997c..bbfab87 100644
--- a/got/got.c
+++ b/got/got.c
@@ -367,16 +367,8 @@ print_commits(struct got_object *root_obj, struct got_object_id *root_id,
entry = TAILQ_FIRST(&commits);
err = print_commit(entry->commit, entry->id, repo, show_patch);
- if (err) {
- while (!TAILQ_EMPTY(&commits)) {
- entry = TAILQ_FIRST(&commits);
- TAILQ_REMOVE(&commits, entry, entry);
- got_object_commit_close(entry->commit);
- free(entry->id);
- free(entry);
- }
+ if (err)
break;
- }
if (limit && --limit == 0)
break;
@@ -421,6 +413,16 @@ print_commits(struct got_object *root_obj, struct got_object_id *root_id,
free(entry);
}
+ if (err) {
+ while (!TAILQ_EMPTY(&commits)) {
+ entry = TAILQ_FIRST(&commits);
+ TAILQ_REMOVE(&commits, entry, entry);
+ got_object_commit_close(entry->commit);
+ free(entry->id);
+ free(entry);
+ }
+ }
+
return err;
}