List for cgit developers and users
 help / color / mirror / Atom feed
From: John Keeping <john@keeping.me.uk>
To: cgit@lists.zx2c4.com
Cc: John Keeping <john@keeping.me.uk>
Subject: [PATCH] treewide: use release_commit_memory()
Date: Sun, 13 Feb 2022 15:34:50 +0000	[thread overview]
Message-ID: <98d70d24a2a37f9bbfec2f25d2c026005757a246.1644766431.git.john@keeping.me.uk> (raw)

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>
---
 ui-atom.c  | 3 +--
 ui-log.c   | 6 ++----
 ui-stats.c | 3 +--
 3 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/ui-atom.c b/ui-atom.c
index 1056f36..83fde7d 100644
--- a/ui-atom.c
+++ b/ui-atom.c
@@ -140,8 +140,7 @@ void cgit_print_atom(char *tip, const char *path, int max_count)
 	}
 	while ((commit = get_revision(&rev)) != NULL) {
 		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 20774bf..db63424 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -489,8 +489,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
 	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 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
 			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 09b3625..40ed6c2 100644
--- a/ui-stats.c
+++ b/ui-stats.c
@@ -241,8 +241,7 @@ static struct string_list collect_stats(const struct cgit_period *period)
 	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;
-- 
2.35.1


                 reply	other threads:[~2022-02-13 15:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=98d70d24a2a37f9bbfec2f25d2c026005757a246.1644766431.git.john@keeping.me.uk \
    --to=john@keeping.me.uk \
    --cc=cgit@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).