Commit 254707814d845a2c4a93c473ad51e9e1b28c716f

Stefan Sperling 2018-04-01T17:36:55

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;