]> git.ipfire.org Git - thirdparty/git.git/commitdiff
repo_logmsg_reencode: fix memory leak when use repo_logmsg_reencode ()
authorLidong Yan <502024330056@smail.nju.edu.cn>
Thu, 5 Jun 2025 06:27:26 +0000 (06:27 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 5 Jun 2025 15:35:22 +0000 (08:35 -0700)
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 <502024330056@smail.nju.edu.cn>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/replay.c
builtin/shortlog.c

index 225cef08807e3304910e7f7b0047573eec792bc6..6172c8aacc9873f417446ad88f7b04901264ef98 100644 (file)
@@ -84,6 +84,7 @@ static struct commit *create_commit(struct repository *repo,
        obj = parse_object(repo, &ret);
 
 out:
+       repo_unuse_commit_buffer(the_repository, based_on, message);
        free_commit_extra_headers(extra);
        free_commit_list(parents);
        strbuf_release(&msg);
index 30075b67be8dac2db7aba793a818f357c7c11cc1..fe15e11497379f916766b87534ff6425113f561c 100644 (file)
@@ -187,7 +187,7 @@ static void insert_records_from_trailers(struct shortlog *log,
                                             ctx->output_encoding);
        body = strstr(commit_buffer, "\n\n");
        if (!body)
-               return;
+               goto out;
 
        trailer_iterator_init(&iter, body);
        while (trailer_iterator_advance(&iter)) {
@@ -206,6 +206,7 @@ static void insert_records_from_trailers(struct shortlog *log,
        }
        trailer_iterator_release(&iter);
 
+out:
        strbuf_release(&ident);
        repo_unuse_commit_buffer(the_repository, commit, commit_buffer);
 }