Skip to content

Conversation

brandb97
Copy link
Contributor

@brandb97 brandb97 commented May 8, 2025

In commit-graph.c:fill_oids_from_packs, if open_pack_index failed, memory allocated in line 1925 by add_packed_git will leak. Simply add close_pack and free(p) will solve this problem.

cc: Patrick Steinhardt ps@pks.im

@brandb97
Copy link
Contributor Author

brandb97 commented May 8, 2025

/submit

Copy link

Submitted as pull.1957.git.git.1746712275566.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-git-1957/brandb97/fix-commit-graph-leak-v1

To fetch this version to local tag pr-git-1957/brandb97/fix-commit-graph-leak-v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-git-1957/brandb97/fix-commit-graph-leak-v1

Copy link

On the Git mailing list, Patrick Steinhardt wrote (reply to this):

On Thu, May 08, 2025 at 01:51:15PM +0000, Lidong Yan via GitGitGadget wrote:
> From: Lidong Yan <502024330056@smail.nju.edu.cn>
> 
> In commit-graph.c line 1930, if open_pack_index failed, memory allocated
> in line 1925 by add_packed_git will leak. Simply add close_pack and
> free(p) will solve this problem.

The same comments apply to this commit message as Junio has already
mentioned in other commits. We don't typically point to exact line
numbers, but rather mention for example the function name.

> diff --git a/commit-graph.c b/commit-graph.c
> index 6394752b0b0..93d867770b0 100644
> --- a/commit-graph.c
> +++ b/commit-graph.c
> @@ -1929,6 +1929,8 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
>  		}
>  		if (open_pack_index(p)) {
>  			ret = error(_("error opening index for %s"), packname.buf);
> +			close_pack(p);
> +			free(p);
>  			goto cleanup;
>  		}
>  		for_each_object_in_pack(p, add_packed_commits, ctx,

The change itself looks correct to me. Thanks!

Patrick

Copy link

User Patrick Steinhardt <ps@pks.im> has been added to the cc: list.

Copy link

On the Git mailing list, lidongyan wrote (reply to this):

Ok, I will replace line number to fill_oids_from_packs in next patch.

> 2025年5月9日 13:38,Patrick Steinhardt <ps@pks.im> 写道:
> 
> On Thu, May 08, 2025 at 01:51:15PM +0000, Lidong Yan via GitGitGadget wrote:
>> From: Lidong Yan <502024330056@smail.nju.edu.cn>
>> 
>> In commit-graph.c line 1930, if open_pack_index failed, memory allocated
>> in line 1925 by add_packed_git will leak. Simply add close_pack and
>> free(p) will solve this problem.
> 
> The same comments apply to this commit message as Junio has already
> mentioned in other commits. We don't typically point to exact line
> numbers, but rather mention for example the function name.
> 
>> diff --git a/commit-graph.c b/commit-graph.c
>> index 6394752b0b0..93d867770b0 100644
>> --- a/commit-graph.c
>> +++ b/commit-graph.c
>> @@ -1929,6 +1929,8 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
>> }
>> if (open_pack_index(p)) {
>> ret = error(_("error opening index for %s"), packname.buf);
>> + close_pack(p);
>> + free(p);
>> goto cleanup;
>> }
>> for_each_object_in_pack(p, add_packed_commits, ctx,
> 
> The change itself looks correct to me. Thanks!
> 
> Patrick
> 

@brandb97 brandb97 force-pushed the fix-commit-graph-leak branch from 72402ab to 190961f Compare May 9, 2025 07:12
@brandb97
Copy link
Contributor Author

brandb97 commented May 9, 2025

/submit

Copy link

Submitted as pull.1957.v2.git.git.1746774869081.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-git-1957/brandb97/fix-commit-graph-leak-v2

To fetch this version to local tag pr-git-1957/brandb97/fix-commit-graph-leak-v2:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-git-1957/brandb97/fix-commit-graph-leak-v2

Copy link

On the Git mailing list, Patrick Steinhardt wrote (reply to this):

On Fri, May 09, 2025 at 07:14:28AM +0000, Lidong Yan via GitGitGadget wrote:
> From: Lidong Yan <502024330056@smail.nju.edu.cn>
> 
> In commit-graph.c:fill_oids_from_packs, if open_pack_index failed,
> memory allocated and returned by add_packed_git will leak. Simply
> add close_pack and free(p) will solve this problem.

One more thing that I missed in the first review: the commit subject
should mention the subsystem as prefix, not the specific function. So It
should e.g. read:

    commit-grap: fix memory leak when `fill_oids_from_packs()` fails

Patrick

In commit-graph.c:fill_oids_from_packs, if open_pack_index failed,
memory allocated and returned by add_packed_git will leak. Simply
add close_pack and free(p) will solve this problem.

Signed-off-by: Lidong Yan <502024330056@smail.nju.edu.cn>
@brandb97 brandb97 force-pushed the fix-commit-graph-leak branch from 190961f to e0dfe69 Compare May 9, 2025 08:29
@brandb97
Copy link
Contributor Author

brandb97 commented May 9, 2025

/submit

Copy link

Submitted as pull.1957.v3.git.git.1746779435536.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-git-1957/brandb97/fix-commit-graph-leak-v3

To fetch this version to local tag pr-git-1957/brandb97/fix-commit-graph-leak-v3:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-git-1957/brandb97/fix-commit-graph-leak-v3

@brandb97 brandb97 changed the title fill_oids_from_packs: fix memory leak when fill_oids_from_packs failed commit-graph: fix memory leak when fill_oids_from_packs failed May 13, 2025
@brandb97 brandb97 changed the title commit-graph: fix memory leak when fill_oids_from_packs failed commit-graph: fix memory leak when fill_oids_from_packs() failed May 13, 2025
Copy link

This patch series was integrated into seen via d691b68.

Copy link

On the Git mailing list, Junio C Hamano wrote (reply to this):

"Lidong Yan via GitGitGadget" <gitgitgadget@gmail.com> writes:

>        ## Commit message ##
>      -    fill_oids_from_packs: fix memory leak when fill_oids_from_packs failed
>      +    commit-grap: fix memory leak when `fill_oids_from_packs()` fails

I'll amend the title to add missing "h" after "grap" while queuing.

Thanks.

Copy link

This branch is now known as ly/commit-graph-fill-oids-leakfix.

Copy link

This patch series was integrated into seen via c20ea1d.

Copy link

There was a status update in the "New Topics" section about the branch ly/commit-graph-fill-oids-leakfix on the Git mailing list:

Leakfix.

Will merge to 'next'.
source: <pull.1957.v3.git.git.1746779435536.gitgitgadget@gmail.com>

Copy link

This patch series was integrated into seen via 68a59b0.

Copy link

This patch series was integrated into seen via 359e7a1.

Copy link

This patch series was integrated into next via 972bbc7.

Copy link

There was a status update in the "Cooking" section about the branch ly/commit-graph-fill-oids-leakfix on the Git mailing list:

Leakfix.

Will merge to 'master'.
source: <pull.1957.v3.git.git.1746779435536.gitgitgadget@gmail.com>

Copy link

This patch series was integrated into seen via 4fb22b4.

Copy link

This patch series was integrated into seen via f2c28d2.

Copy link

This patch series was integrated into seen via cdcee3d.

Copy link

There was a status update in the "Cooking" section about the branch ly/commit-graph-fill-oids-leakfix on the Git mailing list:

Leakfix.

Will merge to 'master'.
source: <pull.1957.v3.git.git.1746779435536.gitgitgadget@gmail.com>

Copy link

This patch series was integrated into seen via b6fa7fb.

Copy link

This patch series was integrated into master via b6fa7fb.

Copy link

This patch series was integrated into next via b6fa7fb.

Copy link

Closed via b6fa7fb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant