Commit 4c520cefc90b10566fcc8a0b006287494a7770e1

Parents: d071f28cfa9a49f3aa6355b17e9d9fa7224ff49f

From: John Keeping <john@keeping.me.uk>
Date: Sun Feb 13 15:34:50 2022 +0700

global: use release_commit_memory()
Instead of calling two separate Git functions to free memory associated
with a commit object, use Git's wrapper which does this.  This also
counts as a potential future bug fix since release_commit_memory() also
resets the parsed state of the commit, meaning any attempt to use it in
the future will correctly fill out the fields again.

release_commit_memory() does not set parents to zero, so keep that for
additional safety in case CGit checks this without calling
parse_commit() again.

Signed-off-by: John Keeping <john@keeping.me.uk>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>

Stats

ui-atom.c +1/-2
ui-log.c +2/-4
ui-stats.c +1/-2

Changeset

 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
diff --git a/ui-atom.c b/ui-atom.c
index 541660d18654b5ff9cc3231e67301fe97b22c851..5f4ad7df3f90b2cba6b5ae9a8632c42e4173d8c1 100644
--- a/ui-atom.c
+++ b/ui-atom.c
@@ -149,8 +149,7 @@ 			html("</updated>\n");
 			first = false;
 		}
 		add_entry(commit, host);
-		free_commit_buffer(the_repository->parsed_objects, commit);
-		free_commit_list(commit->parents);
+		release_commit_memory(the_repository->parsed_objects, commit);
 		commit->parents = NULL;
 	}
 	html("</feed>\n");
diff --git a/ui-log.c b/ui-log.c
index 565929f3f046daaf8db1c89fc3d6928c23119ad0..311304ab80abd60fd957d5bf89a5d1a3d5e008d3 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -489,8 +489,7 @@
 	for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; /* nop */) {
 		if (show_commit(commit, &rev))
 			i++;
-		free_commit_buffer(the_repository->parsed_objects, commit);
-		free_commit_list(commit->parents);
+		release_commit_memory(the_repository->parsed_objects, commit);
 		commit->parents = NULL;
 	}
 
@@ -511,8 +510,7 @@ 		if (show_commit(commit, &rev)) {
 			i++;
 			print_commit(commit, &rev);
 		}
-		free_commit_buffer(the_repository->parsed_objects, commit);
-		free_commit_list(commit->parents);
+		release_commit_memory(the_repository->parsed_objects, commit);
 		commit->parents = NULL;
 	}
 	if (pager) {
diff --git a/ui-stats.c b/ui-stats.c
index 09b3625e7e0cc8e0c13edbf5690f00c9da8ab3a6..40ed6c21df628e178590860f0ef3999d89595331 100644
--- a/ui-stats.c
+++ b/ui-stats.c
@@ -241,8 +241,7 @@ 	prepare_revision_walk(&rev);
 	memset(&authors, 0, sizeof(authors));
 	while ((commit = get_revision(&rev)) != NULL) {
 		add_commit(&authors, commit, period);
-		free_commit_buffer(the_repository->parsed_objects, commit);
-		free_commit_list(commit->parents);
+		release_commit_memory(the_repository->parsed_objects, commit);
 		commit->parents = NULL;
 	}
 	return authors;