Skip to content

Commit a414074

Browse files
committed
repo_logmsg_reencode: fix memory leak when use repo_logmsg_reencode()
pretty.c:repo_logmsg_reencode() allocated memory should be freed with repo_unuse_commit_buffer(). Callers sometimes forgot free it at exit point. Add `repo_unuse_commit_buffer()` in insert_records_from_trailers at builtin/shortlog.c and create_commit at builtin/replay.c Signed-off-by: Lidong Yan <[email protected]>
1 parent 7014b55 commit a414074

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

builtin/replay.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ static struct commit *create_commit(struct repository *repo,
8484
obj = parse_object(repo, &ret);
8585

8686
out:
87+
repo_unuse_commit_buffer(the_repository, based_on, message);
8788
free_commit_extra_headers(extra);
8889
free_commit_list(parents);
8990
strbuf_release(&msg);

builtin/shortlog.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,10 @@ static void insert_records_from_trailers(struct shortlog *log,
186186
commit_buffer = repo_logmsg_reencode(the_repository, commit, NULL,
187187
ctx->output_encoding);
188188
body = strstr(commit_buffer, "\n\n");
189-
if (!body)
189+
if (!body) {
190+
repo_unuse_commit_buffer(the_repository, commit, commit_buffer);
190191
return;
192+
}
191193

192194
trailer_iterator_init(&iter, body);
193195
while (trailer_iterator_advance(&iter)) {

0 commit comments

Comments
 (0)