clean up commit list upon error in print_commits()
diff --git a/got/got.c b/got/got.c
index 9256ea5..fb1724c 100644
--- a/got/got.c
+++ b/got/got.c
@@ -343,8 +343,16 @@ 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)
+ 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);
+ }
break;
+ }
SIMPLEQ_FOREACH(pid, &entry->commit->parent_ids, entry) {
struct got_object *obj;