{"thread":{"id":"63421","subject":"[PATCH] fill_oids_from_packs: fix memory leak when fill_oids_from_packs failed","startedAt":"2025-05-08T13:51:18Z","lastAt":"2025-05-15T21:57:03Z","messageCount":7,"participants":["Lidong Yan via GitGitGadget","Patrick Steinhardt","lidongyan","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"517552","messageId":"pull.1957.git.git.1746712275566.gitgitgadget@gmail.com","threadId":"63421","inReplyTo":null,"subject":"[PATCH] fill_oids_from_packs: fix memory leak when fill_oids_from_packs failed","fromName":"Lidong Yan via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2025-05-08T13:51:15Z","receivedAt":"2025-05-08T13:51:18Z","isPatch":true,"sender":{"key":"yldhome2d2@gmail.com","avatar":"https://avatars.githubusercontent.com/u/77328395?v=4"},"body":"From: Lidong Yan <502024330056@smail.nju.edu.cn>\n\nIn commit-graph.c line 1930, if open_pack_index failed, memory allocated\nin line 1925 by add_packed_git will leak. Simply add close_pack and\nfree(p) will solve this problem.\n\nSigned-off-by: Lidong Yan <502024330056@smail.nju.edu.cn>\n---\n    fill_oids_from_packs: fix memory leak when fill_oids_from_packs failed\n    \n    In commit-graph.c line 1930, if open_pack_index failed, memory allocated\n    in line 1925 by add_packed_git will leak. Simply add close_pack and\n    free(p) will solve this problem.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1957%2Fbrandb97%2Ffix-commit-graph-leak-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1957/brandb97/fix-commit-graph-leak-v1\nPull-Request: https://github.com/git/git/pull/1957\n\n commit-graph.c | 2 ++\n 1 file changed, 2 insertions(+)\n\ndiff --git a/commit-graph.c b/commit-graph.c\nindex 6394752b0b0..93d867770b0 100644\n--- a/commit-graph.c\n+++ b/commit-graph.c\n@@ -1929,6 +1929,8 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,\n \t\t}\n \t\tif (open_pack_index(p)) {\n \t\t\tret = error(_(\"error opening index for %s\"), packname.buf);\n+\t\t\tclose_pack(p);\n+\t\t\tfree(p);\n \t\t\tgoto cleanup;\n \t\t}\n \t\tfor_each_object_in_pack(p, add_packed_commits, ctx,\n\nbase-commit: 6f84262c44a89851c3ae5a6e4c1a9d06b2068d75\n-- \ngitgitgadget\n"},{"id":"517622","messageId":"aB2U2Jb8hXW3Hwt3@pks.im","threadId":"63421","inReplyTo":"pull.1957.git.git.1746712275566.gitgitgadget@gmail.com","subject":"Re: [PATCH] fill_oids_from_packs: fix memory leak when fill_oids_from_packs failed","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-05-09T05:38:32Z","receivedAt":"2025-05-09T05:38:41Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, May 08, 2025 at 01:51:15PM +0000, Lidong Yan via GitGitGadget wrote:\n> From: Lidong Yan <502024330056@smail.nju.edu.cn>\n> \n> In commit-graph.c line 1930, if open_pack_index failed, memory allocated\n> in line 1925 by add_packed_git will leak. Simply add close_pack and\n> free(p) will solve this problem.\n\nThe same comments apply to this commit message as Junio has already\nmentioned in other commits. We don't typically point to exact line\nnumbers, but rather mention for example the function name.\n\n> diff --git a/commit-graph.c b/commit-graph.c\n> index 6394752b0b0..93d867770b0 100644\n> --- a/commit-graph.c\n> +++ b/commit-graph.c\n> @@ -1929,6 +1929,8 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,\n>  \t\t}\n>  \t\tif (open_pack_index(p)) {\n>  \t\t\tret = error(_(\"error opening index for %s\"), packname.buf);\n> +\t\t\tclose_pack(p);\n> +\t\t\tfree(p);\n>  \t\t\tgoto cleanup;\n>  \t\t}\n>  \t\tfor_each_object_in_pack(p, add_packed_commits, ctx,\n\nThe change itself looks correct to me. Thanks!\n\nPatrick\n"},{"id":"517626","messageId":"4AC31140-BBC8-4275-B18C-37D5AAE45B6B@smail.nju.edu.cn","threadId":"63421","inReplyTo":"aB2U2Jb8hXW3Hwt3@pks.im","subject":"Re: [PATCH] fill_oids_from_packs: fix memory leak when fill_oids_from_packs failed","fromName":"lidongyan","fromEmail":"502024330056@smail.nju.edu.cn","sentAt":"2025-05-09T07:06:01Z","receivedAt":"2025-05-09T07:06:34Z","isPatch":true,"sender":{"key":"502024330056@smail.nju.edu.cn","avatar":"https://avatars.githubusercontent.com/u/77328395?v=4"},"body":"Ok, I will replace line number to fill_oids_from_packs in next patch.\n\n> 2025年5月9日 13:38，Patrick Steinhardt <ps@pks.im> 写道：\n> \n> On Thu, May 08, 2025 at 01:51:15PM +0000, Lidong Yan via GitGitGadget wrote:\n>> From: Lidong Yan <502024330056@smail.nju.edu.cn>\n>> \n>> In commit-graph.c line 1930, if open_pack_index failed, memory allocated\n>> in line 1925 by add_packed_git will leak. Simply add close_pack and\n>> free(p) will solve this problem.\n> \n> The same comments apply to this commit message as Junio has already\n> mentioned in other commits. We don't typically point to exact line\n> numbers, but rather mention for example the function name.\n> \n>> diff --git a/commit-graph.c b/commit-graph.c\n>> index 6394752b0b0..93d867770b0 100644\n>> --- a/commit-graph.c\n>> +++ b/commit-graph.c\n>> @@ -1929,6 +1929,8 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,\n>> }\n>> if (open_pack_index(p)) {\n>> ret = error(_(\"error opening index for %s\"), packname.buf);\n>> + close_pack(p);\n>> + free(p);\n>> goto cleanup;\n>> }\n>> for_each_object_in_pack(p, add_packed_commits, ctx,\n> \n> The change itself looks correct to me. Thanks!\n> \n> Patrick\n> \n\n"},{"id":"517627","messageId":"pull.1957.v2.git.git.1746774869081.gitgitgadget@gmail.com","threadId":"63421","inReplyTo":"pull.1957.git.git.1746712275566.gitgitgadget@gmail.com","subject":"[PATCH v2] fill_oids_from_packs: fix memory leak when fill_oids_from_packs failed","fromName":"Lidong Yan via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2025-05-09T07:14:28Z","receivedAt":"2025-05-09T07:14:32Z","isPatch":true,"sender":{"key":"yldhome2d2@gmail.com","avatar":"https://avatars.githubusercontent.com/u/77328395?v=4"},"body":"From: Lidong Yan <502024330056@smail.nju.edu.cn>\n\nIn commit-graph.c:fill_oids_from_packs, if open_pack_index failed,\nmemory allocated and returned by add_packed_git will leak. Simply\nadd close_pack and free(p) will solve this problem.\n\nSigned-off-by: Lidong Yan <502024330056@smail.nju.edu.cn>\n---\n    fill_oids_from_packs: fix memory leak when fill_oids_from_packs failed\n    \n    In commit-graph.c line 1930, if open_pack_index failed, memory allocated\n    in line 1925 by add_packed_git will leak. Simply add close_pack and\n    free(p) will solve this problem.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1957%2Fbrandb97%2Ffix-commit-graph-leak-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1957/brandb97/fix-commit-graph-leak-v2\nPull-Request: https://github.com/git/git/pull/1957\n\nRange-diff vs v1:\n\n 1:  72402abe900 ! 1:  190961fe942 fill_oids_from_packs: fix memory leak when fill_oids_from_packs failed\n     @@ Metadata\n       ## Commit message ##\n          fill_oids_from_packs: fix memory leak when fill_oids_from_packs failed\n      \n     -    In commit-graph.c line 1930, if open_pack_index failed, memory allocated\n     -    in line 1925 by add_packed_git will leak. Simply add close_pack and\n     -    free(p) will solve this problem.\n     +    In commit-graph.c:fill_oids_from_packs, if open_pack_index failed,\n     +    memory allocated and returned by add_packed_git will leak. Simply\n     +    add close_pack and free(p) will solve this problem.\n      \n          Signed-off-by: Lidong Yan <502024330056@smail.nju.edu.cn>\n      \n\n\n commit-graph.c | 2 ++\n 1 file changed, 2 insertions(+)\n\ndiff --git a/commit-graph.c b/commit-graph.c\nindex 6394752b0b0..93d867770b0 100644\n--- a/commit-graph.c\n+++ b/commit-graph.c\n@@ -1929,6 +1929,8 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,\n \t\t}\n \t\tif (open_pack_index(p)) {\n \t\t\tret = error(_(\"error opening index for %s\"), packname.buf);\n+\t\t\tclose_pack(p);\n+\t\t\tfree(p);\n \t\t\tgoto cleanup;\n \t\t}\n \t\tfor_each_object_in_pack(p, add_packed_commits, ctx,\n\nbase-commit: 6f84262c44a89851c3ae5a6e4c1a9d06b2068d75\n-- \ngitgitgadget\n"},{"id":"517633","messageId":"aB2765DnIjb1xDQW@pks.im","threadId":"63421","inReplyTo":"pull.1957.v2.git.git.1746774869081.gitgitgadget@gmail.com","subject":"Re: [PATCH v2] fill_oids_from_packs: fix memory leak when fill_oids_from_packs failed","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-05-09T08:25:15Z","receivedAt":"2025-05-09T08:25:19Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Fri, May 09, 2025 at 07:14:28AM +0000, Lidong Yan via GitGitGadget wrote:\n> From: Lidong Yan <502024330056@smail.nju.edu.cn>\n> \n> In commit-graph.c:fill_oids_from_packs, if open_pack_index failed,\n> memory allocated and returned by add_packed_git will leak. Simply\n> add close_pack and free(p) will solve this problem.\n\nOne more thing that I missed in the first review: the commit subject\nshould mention the subsystem as prefix, not the specific function. So It\nshould e.g. read:\n\n    commit-grap: fix memory leak when `fill_oids_from_packs()` fails\n\nPatrick\n"},{"id":"517634","messageId":"pull.1957.v3.git.git.1746779435536.gitgitgadget@gmail.com","threadId":"63421","inReplyTo":"pull.1957.v2.git.git.1746774869081.gitgitgadget@gmail.com","subject":"[PATCH v3] commit-grap: fix memory leak when `fill_oids_from_packs()` fails","fromName":"Lidong Yan via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2025-05-09T08:30:35Z","receivedAt":"2025-05-09T08:30:39Z","isPatch":true,"sender":{"key":"yldhome2d2@gmail.com","avatar":"https://avatars.githubusercontent.com/u/77328395?v=4"},"body":"From: Lidong Yan <502024330056@smail.nju.edu.cn>\n\nIn commit-graph.c:fill_oids_from_packs, if open_pack_index failed,\nmemory allocated and returned by add_packed_git will leak. Simply\nadd close_pack and free(p) will solve this problem.\n\nSigned-off-by: Lidong Yan <502024330056@smail.nju.edu.cn>\n---\n    fill_oids_from_packs: fix memory leak when fill_oids_from_packs failed\n    \n    In commit-graph.c line 1930, if open_pack_index failed, memory allocated\n    in line 1925 by add_packed_git will leak. Simply add close_pack and\n    free(p) will solve this problem.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1957%2Fbrandb97%2Ffix-commit-graph-leak-v3\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1957/brandb97/fix-commit-graph-leak-v3\nPull-Request: https://github.com/git/git/pull/1957\n\nRange-diff vs v2:\n\n 1:  190961fe942 ! 1:  e0dfe69f504 fill_oids_from_packs: fix memory leak when fill_oids_from_packs failed\n     @@ Metadata\n      Author: Lidong Yan <502024330056@smail.nju.edu.cn>\n      \n       ## Commit message ##\n     -    fill_oids_from_packs: fix memory leak when fill_oids_from_packs failed\n     +    commit-grap: fix memory leak when `fill_oids_from_packs()` fails\n      \n          In commit-graph.c:fill_oids_from_packs, if open_pack_index failed,\n          memory allocated and returned by add_packed_git will leak. Simply\n\n\n commit-graph.c | 2 ++\n 1 file changed, 2 insertions(+)\n\ndiff --git a/commit-graph.c b/commit-graph.c\nindex 6394752b0b0..93d867770b0 100644\n--- a/commit-graph.c\n+++ b/commit-graph.c\n@@ -1929,6 +1929,8 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,\n \t\t}\n \t\tif (open_pack_index(p)) {\n \t\t\tret = error(_(\"error opening index for %s\"), packname.buf);\n+\t\t\tclose_pack(p);\n+\t\t\tfree(p);\n \t\t\tgoto cleanup;\n \t\t}\n \t\tfor_each_object_in_pack(p, add_packed_commits, ctx,\n\nbase-commit: 6f84262c44a89851c3ae5a6e4c1a9d06b2068d75\n-- \ngitgitgadget\n"},{"id":"518191","messageId":"xmqqr00py1ug.fsf@gitster.g","threadId":"63421","inReplyTo":"pull.1957.v3.git.git.1746779435536.gitgitgadget@gmail.com","subject":"Re: [PATCH v3] commit-grap: fix memory leak when `fill_oids_from_packs()` fails","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-05-15T21:56:55Z","receivedAt":"2025-05-15T21:57:03Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Lidong Yan via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n>        ## Commit message ##\n>      -    fill_oids_from_packs: fix memory leak when fill_oids_from_packs failed\n>      +    commit-grap: fix memory leak when `fill_oids_from_packs()` fails\n\nI'll amend the title to add missing \"h\" after \"grap\" while queuing.\n\nThanks.\n"}]}