introduce got_ref_list_free() and use it in got and tog
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
diff --git a/got/got.c b/got/got.c
index 35d5afb..0e10c1f 100644
--- a/got/got.c
+++ b/got/got.c
@@ -945,6 +945,7 @@ done:
if (error == NULL)
error = repo_error;
}
+ got_ref_list_free(&refs);
return error;
}
@@ -1704,6 +1705,7 @@ list_refs(struct got_repository *repo)
free(refstr);
}
+ got_ref_list_free(&refs);
return NULL;
}
diff --git a/include/got_reference.h b/include/got_reference.h
index f5c67f2..239c9df 100644
--- a/include/got_reference.h
+++ b/include/got_reference.h
@@ -74,6 +74,9 @@ SIMPLEQ_HEAD(got_reflist_head, got_reflist_entry);
const struct got_error *got_ref_list(struct got_reflist_head *,
struct got_repository *);
+/* Free all references on a ref list. */
+void got_ref_list_free(struct got_reflist_head *);
+
/* Write a reference to its on-disk path in the repository. */
const struct got_error *got_ref_write(struct got_reference *,
struct got_repository *);
diff --git a/lib/reference.c b/lib/reference.c
index ae3b86b..f66bd47 100644
--- a/lib/reference.c
+++ b/lib/reference.c
@@ -702,6 +702,21 @@ done:
return err;
}
+void
+got_ref_list_free(struct got_reflist_head *refs)
+{
+ struct got_reflist_entry *re;
+
+ while (!SIMPLEQ_EMPTY(refs)) {
+ re = SIMPLEQ_FIRST(refs);
+ SIMPLEQ_REMOVE_HEAD(refs, entry);
+ got_ref_close(re->ref);
+ free(re->id);
+ free(re);
+ }
+
+}
+
const struct got_error *
got_ref_write(struct got_reference *ref, struct got_repository *repo)
{
diff --git a/tog/tog.c b/tog/tog.c
index 421f8fe..9086729 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -1923,6 +1923,7 @@ done:
got_repo_close(repo);
if (worktree)
got_worktree_close(worktree);
+ got_ref_list_free(&refs);
return error;
}
@@ -2517,6 +2518,7 @@ cmd_diff(int argc, char *argv[])
error = view_loop(view);
done:
got_repo_close(repo);
+ got_ref_list_free(&refs);
return error;
}
@@ -3288,6 +3290,7 @@ done:
got_worktree_close(worktree);
if (repo)
got_repo_close(repo);
+ got_ref_list_free(&refs);
return error;
}
@@ -3938,6 +3941,7 @@ done:
got_object_tree_close(tree);
if (repo)
got_repo_close(repo);
+ got_ref_list_free(&refs);
return error;
}