Skip to content

Commit 61372dd

Browse files
brandb97gitster
authored andcommitted
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]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0d42fbd commit 61372dd

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ static void insert_records_from_trailers(struct shortlog *log,
187187
ctx->output_encoding);
188188
body = strstr(commit_buffer, "\n\n");
189189
if (!body)
190-
return;
190+
goto out;
191191

192192
trailer_iterator_init(&iter, body);
193193
while (trailer_iterator_advance(&iter)) {
@@ -206,6 +206,7 @@ static void insert_records_from_trailers(struct shortlog *log,
206206
}
207207
trailer_iterator_release(&iter);
208208

209+
out:
209210
strbuf_release(&ident);
210211
repo_unuse_commit_buffer(the_repository, commit, commit_buffer);
211212
}

0 commit comments

Comments
 (0)