* [PATCH] revision: fix memory leak in prepare_show_merge()
@ 2025-06-04 3:08 Lidong Yan via GitGitGadget
2025-06-04 7:48 ` Patrick Steinhardt
2025-06-09 8:16 ` [PATCH v2] " Lidong Yan via GitGitGadget
0 siblings, 2 replies; 12+ messages in thread
From: Lidong Yan via GitGitGadget @ 2025-06-04 3:08 UTC (permalink / raw)
To: git; +Cc: Lidong Yan, Lidong Yan
From: Lidong Yan <502024330056@smail.nju.edu.cn>
In revision.c:prepare_show_merge(), we allocated an array in prune
but forget to free it. Since parse_pathspec is not responsible to
free prune, we should add `free(prune)` in the end of prepare_show_merge().
Signed-off-by: Lidong Yan <502024330056@smail.nju.edu.cn>
---
revision: fix memory leak in prepare_show_merge()
In revision.c:prepare_show_merge(), we allocated an array in prune but
forget to free it. Since parse_pathspec is not responsible to free
prune, we should add free(prune) in the end of prepare_show_merge().
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1989%2Fbrandb97%2Ffix-revision-leak-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1989/brandb97/fix-revision-leak-v1
Pull-Request: https://github.com/git/git/pull/1989
revision.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/revision.c b/revision.c
index 2c36a9c179e..afee1111961 100644
--- a/revision.c
+++ b/revision.c
@@ -2060,6 +2060,7 @@ static void prepare_show_merge(struct rev_info *revs)
parse_pathspec(&revs->prune_data, PATHSPEC_ALL_MAGIC & ~PATHSPEC_LITERAL,
PATHSPEC_PREFER_FULL | PATHSPEC_LITERAL_PATH, "", prune);
revs->limited = 1;
+ free(prune);
}
static int dotdot_missing(const char *arg, char *dotdot,
base-commit: 7014b55638da979331baf8dc31c4e1d697cf2d67
--
gitgitgadget
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH] revision: fix memory leak in prepare_show_merge()
2025-06-04 3:08 [PATCH] revision: fix memory leak in prepare_show_merge() Lidong Yan via GitGitGadget
@ 2025-06-04 7:48 ` Patrick Steinhardt
2025-06-04 7:53 ` lidongyan
2025-06-05 20:56 ` Junio C Hamano
2025-06-09 8:16 ` [PATCH v2] " Lidong Yan via GitGitGadget
1 sibling, 2 replies; 12+ messages in thread
From: Patrick Steinhardt @ 2025-06-04 7:48 UTC (permalink / raw)
To: Lidong Yan via GitGitGadget; +Cc: git, Lidong Yan
On Wed, Jun 04, 2025 at 03:08:56AM +0000, Lidong Yan via GitGitGadget wrote:
> From: Lidong Yan <502024330056@smail.nju.edu.cn>
>
> In revision.c:prepare_show_merge(), we allocated an array in prune
> but forget to free it. Since parse_pathspec is not responsible to
> free prune, we should add `free(prune)` in the end of prepare_show_merge().
That is a rather obvious memory leak indeed. Do you know why we never
detected the leak in our CI? Is this code path not exercised at all by
our tests?
Patrick
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] revision: fix memory leak in prepare_show_merge()
2025-06-04 7:48 ` Patrick Steinhardt
@ 2025-06-04 7:53 ` lidongyan
2025-06-04 8:06 ` Patrick Steinhardt
2025-06-05 20:56 ` Junio C Hamano
1 sibling, 1 reply; 12+ messages in thread
From: lidongyan @ 2025-06-04 7:53 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: Lidong Yan via GitGitGadget, git
2025年6月4日 15:48,Patrick Steinhardt <ps@pks.im> 写道:
>
> On Wed, Jun 04, 2025 at 03:08:56AM +0000, Lidong Yan via GitGitGadget wrote:
>> From: Lidong Yan <502024330056@smail.nju.edu.cn>
>>
>> In revision.c:prepare_show_merge(), we allocated an array in prune
>> but forget to free it. Since parse_pathspec is not responsible to
>> free prune, we should add `free(prune)` in the end of prepare_show_merge().
>
> That is a rather obvious memory leak indeed. Do you know why we never
> detected the leak in our CI? Is this code path not exercised at all by
> our tests?
>
> Patrick
>
I don’t know why CI test doesn’t cover this leak, but I am happy to add
a prereq test for this case.
p.s. I also like to ask that it there anyway to run test locally? How do you
developers normally run test without open an pull request.
Thanks,
Lidong
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] revision: fix memory leak in prepare_show_merge()
2025-06-04 7:53 ` lidongyan
@ 2025-06-04 8:06 ` Patrick Steinhardt
2025-06-04 10:25 ` lidongyan
0 siblings, 1 reply; 12+ messages in thread
From: Patrick Steinhardt @ 2025-06-04 8:06 UTC (permalink / raw)
To: lidongyan; +Cc: Lidong Yan via GitGitGadget, git
On Wed, Jun 04, 2025 at 03:53:44PM +0800, lidongyan wrote:
> 2025年6月4日 15:48,Patrick Steinhardt <ps@pks.im> 写道:
> >
> > On Wed, Jun 04, 2025 at 03:08:56AM +0000, Lidong Yan via GitGitGadget wrote:
> >> From: Lidong Yan <502024330056@smail.nju.edu.cn>
> >>
> >> In revision.c:prepare_show_merge(), we allocated an array in prune
> >> but forget to free it. Since parse_pathspec is not responsible to
> >> free prune, we should add `free(prune)` in the end of prepare_show_merge().
> >
> > That is a rather obvious memory leak indeed. Do you know why we never
> > detected the leak in our CI? Is this code path not exercised at all by
> > our tests?
> >
> > Patrick
> >
>
> I don’t know why CI test doesn’t cover this leak, but I am happy to add
> a prereq test for this case.
>
> p.s. I also like to ask that it there anyway to run test locally? How do you
> developers normally run test without open an pull request.
Do you mean the test suite in general or leak tests in particular? In
any case, you can of course run both of these locally. You can do so
either by using Make:
# Run tests.
$ make test
# Run tests with the leak checking enabled.
$ make test SANITIZE=leak
Or with Meson:
# Create the build directory and execute tests.
$ meson setup build
$ meson test -C build
# Create a second build directory, this time with leak checking
# enabled.
$ meson setup build-leaks -Db_sanitize=leak
$ meson test -C build-leaks
Patrick
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH] revision: fix memory leak in prepare_show_merge()
2025-06-04 8:06 ` Patrick Steinhardt
@ 2025-06-04 10:25 ` lidongyan
0 siblings, 0 replies; 12+ messages in thread
From: lidongyan @ 2025-06-04 10:25 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: Lidong Yan via GitGitGadget, git
2025年6月4日 16:06,Patrick Steinhardt <ps@pks.im> 写道:
>
> On Wed, Jun 04, 2025 at 03:53:44PM +0800, lidongyan wrote:
>> 2025年6月4日 15:48,Patrick Steinhardt <ps@pks.im> 写道:
>>>
>>> On Wed, Jun 04, 2025 at 03:08:56AM +0000, Lidong Yan via GitGitGadget wrote:
>>>> From: Lidong Yan <502024330056@smail.nju.edu.cn>
>>>>
>>>> In revision.c:prepare_show_merge(), we allocated an array in prune
>>>> but forget to free it. Since parse_pathspec is not responsible to
>>>> free prune, we should add `free(prune)` in the end of prepare_show_merge().
>>>
>>> That is a rather obvious memory leak indeed. Do you know why we never
>>> detected the leak in our CI? Is this code path not exercised at all by
>>> our tests?
>>>
>>> Patrick
>>>
>>
>> I don’t know why CI test doesn’t cover this leak, but I am happy to add
>> a prereq test for this case.
>>
>> p.s. I also like to ask that it there anyway to run test locally? How do you
>> developers normally run test without open an pull request.
>
> Do you mean the test suite in general or leak tests in particular? In
> any case, you can of course run both of these locally. You can do so
> either by using Make:
>
> # Run tests.
> $ make test
> # Run tests with the leak checking enabled.
> $ make test SANITIZE=leak
>
> Or with Meson:
>
> # Create the build directory and execute tests.
> $ meson setup build
> $ meson test -C build
>
> # Create a second build directory, this time with leak checking
> # enabled.
> $ meson setup build-leaks -Db_sanitize=leak
> $ meson test -C build-leaks
>
> Patrick
Got it, thank you
Lidong
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] revision: fix memory leak in prepare_show_merge()
2025-06-04 7:48 ` Patrick Steinhardt
2025-06-04 7:53 ` lidongyan
@ 2025-06-05 20:56 ` Junio C Hamano
2025-06-06 7:31 ` lidongyan
1 sibling, 1 reply; 12+ messages in thread
From: Junio C Hamano @ 2025-06-05 20:56 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: Lidong Yan via GitGitGadget, git, Lidong Yan
Patrick Steinhardt <ps@pks.im> writes:
> On Wed, Jun 04, 2025 at 03:08:56AM +0000, Lidong Yan via GitGitGadget wrote:
>> From: Lidong Yan <502024330056@smail.nju.edu.cn>
>>
>> In revision.c:prepare_show_merge(), we allocated an array in prune
>> but forget to free it. Since parse_pathspec is not responsible to
>> free prune, we should add `free(prune)` in the end of prepare_show_merge().
>
> That is a rather obvious memory leak indeed. Do you know why we never
> detected the leak in our CI? Is this code path not exercised at all by
> our tests?
I think we have no "show --merge" test. Something like this may be
minimally sufficient.
t/t7007-show.sh | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git c/t/t7007-show.sh w/t/t7007-show.sh
index d6cc69e0f2..99f4d0b963 100755
--- c/t/t7007-show.sh
+++ w/t/t7007-show.sh
@@ -167,4 +167,19 @@ test_expect_success 'show --graph is forbidden' '
test_must_fail git show --graph HEAD
'
+test_expect_success 'unmerged index' '
+ git reset --hard &&
+ git commit --allow-empty -m initial &&
+ git rev-parse HEAD >.git/MERGE_HEAD &&
+ blob1=$(echo hello | git hash-object -w --stdin) &&
+ blob2=$(echo goodbye | git hash-object -w --stdin) &&
+ blob3=$(echo world | git hash-object -w --stdin) &&
+ git update-index --add --index-info <<-EOF &&
+ 100644 $blob1 1 conflicting
+ 100644 $blob2 2 conflicting
+ 100755 $blob3 3 conflicting
+ EOF
+ git show --merge HEAD
+'
+
test_done
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH] revision: fix memory leak in prepare_show_merge()
2025-06-05 20:56 ` Junio C Hamano
@ 2025-06-06 7:31 ` lidongyan
2025-06-06 16:47 ` Junio C Hamano
0 siblings, 1 reply; 12+ messages in thread
From: lidongyan @ 2025-06-06 7:31 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Patrick Steinhardt, Lidong Yan via GitGitGadget, git
2025年6月6日 04:56,Junio C Hamano <gitster@pobox.com> 写道:
>
> Patrick Steinhardt <ps@pks.im> writes:
>
>> On Wed, Jun 04, 2025 at 03:08:56AM +0000, Lidong Yan via GitGitGadget wrote:
>>> From: Lidong Yan <502024330056@smail.nju.edu.cn>
>>>
>>> In revision.c:prepare_show_merge(), we allocated an array in prune
>>> but forget to free it. Since parse_pathspec is not responsible to
>>> free prune, we should add `free(prune)` in the end of prepare_show_merge().
>>
>> That is a rather obvious memory leak indeed. Do you know why we never
>> detected the leak in our CI? Is this code path not exercised at all by
>> our tests?
>
> I think we have no "show --merge" test. Something like this may be
> minimally sufficient.
>
> t/t7007-show.sh | 15 +++++++++++++++
> 1 file changed, 15 insertions(+)
>
> diff --git c/t/t7007-show.sh w/t/t7007-show.sh
> index d6cc69e0f2..99f4d0b963 100755
> --- c/t/t7007-show.sh
> +++ w/t/t7007-show.sh
> @@ -167,4 +167,19 @@ test_expect_success 'show --graph is forbidden' '
> test_must_fail git show --graph HEAD
> '
>
> +test_expect_success 'unmerged index' '
> + git reset --hard &&
> + git commit --allow-empty -m initial &&
> + git rev-parse HEAD >.git/MERGE_HEAD &&
> + blob1=$(echo hello | git hash-object -w --stdin) &&
> + blob2=$(echo goodbye | git hash-object -w --stdin) &&
> + blob3=$(echo world | git hash-object -w --stdin) &&
> + git update-index --add --index-info <<-EOF &&
> + 100644 $blob1 1 conflicting
> + 100644 $blob2 2 conflicting
> + 100755 $blob3 3 conflicting
> + EOF
> + git show --merge HEAD
> +'
> +
> test_done
>
I could add this test case into my patch. Though I don’t understand
> + git rev-parse HEAD >.git/MERGE_HEAD &&
If HEAD is equal to MERGE_HEAD. Would git show —merge still
works as usual? How about something like this
diff --git a/t/t7007-show.sh b/t/t7007-show.sh
index d6cc69e0f2..f693b6e24b 100755
--- a/t/t7007-show.sh
+++ b/t/t7007-show.sh
@@ -167,4 +167,28 @@ test_expect_success 'show --graph is forbidden' '
test_must_fail git show --graph HEAD
'
+test_expect_success 'unmerged index' '
+ git reset --hard &&
+
+ git switch -C base &&
+ echo "base" > conflicting &&
+ git add conflicting &&
+ git commit -m "base" &&
+
+ git branch hello &&
+ git branch goodbye &&
+
+ git switch hello &&
+ echo "hello" > conflicting &&
+ git commit -am "hello" &&
+
+ git switch goodbye &&
+ echo "goodbye" > conflicting &&
+ git commit -am "goodbye" &&
+
+ git switch hello &&
+ test_must_fail git merge goodbye &&
+ git show --merge HEAD
+'
+
test_done
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH] revision: fix memory leak in prepare_show_merge()
2025-06-06 7:31 ` lidongyan
@ 2025-06-06 16:47 ` Junio C Hamano
2025-06-09 3:10 ` lidongyan
0 siblings, 1 reply; 12+ messages in thread
From: Junio C Hamano @ 2025-06-06 16:47 UTC (permalink / raw)
To: lidongyan; +Cc: Patrick Steinhardt, Lidong Yan via GitGitGadget, git
lidongyan <502024330056@smail.nju.edu.cn> writes:
> I could add this test case into my patch. Though I don’t understand
>> + git rev-parse HEAD >.git/MERGE_HEAD &&
That was not about telling "show --merge" to work on any meaningful
data and to produce any useful output. I knew the step to prepare
for "show --merge" was leaky, so I gave a very minimum that can tickle
that codepath. I wasn't of course proud of the direct manipulation
of the filesystem (as recent "git update-ref MERGE_HEAD HEAD" would
not even allow us to do this, sheesh, not very convenient).
If you came up with a sequence that produces a situation to use the
"git show --merge" command in a more realistic way, like below, that
is wonderful.
> If HEAD is equal to MERGE_HEAD. Would git show —merge still
> works as usual? How about something like this
>
> diff --git a/t/t7007-show.sh b/t/t7007-show.sh
> index d6cc69e0f2..f693b6e24b 100755
> --- a/t/t7007-show.sh
> +++ b/t/t7007-show.sh
> @@ -167,4 +167,28 @@ test_expect_success 'show --graph is forbidden' '
> test_must_fail git show --graph HEAD
> '
>
> +test_expect_success 'unmerged index' '
> + git reset --hard &&
> +
> + git switch -C base &&
> + echo "base" > conflicting &&
> + git add conflicting &&
> + git commit -m "base" &&
> +
> + git branch hello &&
> + git branch goodbye &&
> +
> + git switch hello &&
> + echo "hello" > conflicting &&
> + git commit -am "hello" &&
> +
> + git switch goodbye &&
> + echo "goodbye" > conflicting &&
> + git commit -am "goodbye" &&
> +
> + git switch hello &&
> + test_must_fail git merge goodbye &&
> + git show --merge HEAD
> +'
> +
> test_done
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] revision: fix memory leak in prepare_show_merge()
2025-06-06 16:47 ` Junio C Hamano
@ 2025-06-09 3:10 ` lidongyan
0 siblings, 0 replies; 12+ messages in thread
From: lidongyan @ 2025-06-09 3:10 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Patrick Steinhardt, Lidong Yan via GitGitGadget, git
2025年6月7日 00:47,Junio C Hamano <gitster@pobox.com> 写道:
>
> lidongyan <502024330056@smail.nju.edu.cn> writes:
>
>> I could add this test case into my patch. Though I don’t understand
>>> + git rev-parse HEAD >.git/MERGE_HEAD &&
>
> That was not about telling "show --merge" to work on any meaningful
> data and to produce any useful output. I knew the step to prepare
> for "show --merge" was leaky, so I gave a very minimum that can tickle
> that codepath. I wasn't of course proud of the direct manipulation
> of the filesystem (as recent "git update-ref MERGE_HEAD HEAD" would
> not even allow us to do this, sheesh, not very convenient).
I understand. `show —merge` means the codepath must go through prepare_show_merge()
And `update-index` with index which has stage greater than 0 let
prepare_show_merge() go through loop and add index to prune. Thus
cause a leak.
>
> If you came up with a sequence that produces a situation to use the
> "git show --merge" command in a more realistic way, like below, that
> is wonderful.
>
>> If HEAD is equal to MERGE_HEAD. Would git show —merge still
>> works as usual? How about something like this
>>
>> diff --git a/t/t7007-show.sh b/t/t7007-show.sh
>> index d6cc69e0f2..f693b6e24b 100755
>> --- a/t/t7007-show.sh
>> +++ b/t/t7007-show.sh
>> @@ -167,4 +167,28 @@ test_expect_success 'show --graph is forbidden' '
>> test_must_fail git show --graph HEAD
>> '
>>
>> +test_expect_success 'unmerged index' '
>> + git reset --hard &&
>> +
>> + git switch -C base &&
>> + echo "base" > conflicting &&
>> + git add conflicting &&
>> + git commit -m "base" &&
>> +
>> + git branch hello &&
>> + git branch goodbye &&
>> +
>> + git switch hello &&
>> + echo "hello" > conflicting &&
>> + git commit -am "hello" &&
>> +
>> + git switch goodbye &&
>> + echo "goodbye" > conflicting &&
>> + git commit -am "goodbye" &&
>> +
>> + git switch hello &&
>> + test_must_fail git merge goodbye &&
>> + git show --merge HEAD
>> +'
>> +
>> test_done
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2] revision: fix memory leak in prepare_show_merge()
2025-06-04 3:08 [PATCH] revision: fix memory leak in prepare_show_merge() Lidong Yan via GitGitGadget
2025-06-04 7:48 ` Patrick Steinhardt
@ 2025-06-09 8:16 ` Lidong Yan via GitGitGadget
2025-06-09 20:48 ` Junio C Hamano
2025-06-10 0:37 ` [PATCH v3] " Lidong Yan via GitGitGadget
1 sibling, 2 replies; 12+ messages in thread
From: Lidong Yan via GitGitGadget @ 2025-06-09 8:16 UTC (permalink / raw)
To: git; +Cc: Patrick Steinhardt, Lidong Yan, Lidong Yan
From: Lidong Yan <502024330056@smail.nju.edu.cn>
In revision.c:prepare_show_merge(), we allocated an array in prune
but forget to free it. Since parse_pathspec is not responsible to
free prune, we should add `free(prune)` in the end of prepare_show_merge().
Signed-off-by: Lidong Yan <502024330056@smail.nju.edu.cn>
---
revision: fix memory leak in prepare_show_merge()
In revision.c:prepare_show_merge(), we allocated an array in prune but
forget to free it. Since parse_pathspec is not responsible to free
prune, we should add free(prune) in the end of prepare_show_merge().
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1989%2Fbrandb97%2Ffix-revision-leak-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1989/brandb97/fix-revision-leak-v2
Pull-Request: https://github.com/git/git/pull/1989
Range-diff vs v1:
1: 5d213e2c11c ! 1: 61a2d98dad9 revision: fix memory leak in prepare_show_merge()
@@ revision.c: static void prepare_show_merge(struct rev_info *revs)
}
static int dotdot_missing(const char *arg, char *dotdot,
+
+ ## t/t7007-show.sh ##
+@@ t/t7007-show.sh: test_expect_success 'show --graph is forbidden' '
+ test_must_fail git show --graph HEAD
+ '
+
++test_expect_success 'show unmerged index' '
++ git reset --hard &&
++
++ git switch -C base &&
++ echo "base" > conflicting &&
++ git add conflicting &&
++ git commit -m "base" &&
++
++ git branch hello &&
++ git branch goodbye &&
++
++ git switch hello &&
++ echo "hello" > conflicting &&
++ git commit -am "hello" &&
++
++ git switch goodbye &&
++ echo "goodbye" > conflicting &&
++ git commit -am "goodbye" &&
++
++ git switch hello &&
++ test_must_fail git merge goodbye &&
++ git show --merge HEAD
++'
++
+ test_done
revision.c | 1 +
t/t7007-show.sh | 24 ++++++++++++++++++++++++
2 files changed, 25 insertions(+)
diff --git a/revision.c b/revision.c
index 2c36a9c179ef..afee11119615 100644
--- a/revision.c
+++ b/revision.c
@@ -2060,6 +2060,7 @@ static void prepare_show_merge(struct rev_info *revs)
parse_pathspec(&revs->prune_data, PATHSPEC_ALL_MAGIC & ~PATHSPEC_LITERAL,
PATHSPEC_PREFER_FULL | PATHSPEC_LITERAL_PATH, "", prune);
revs->limited = 1;
+ free(prune);
}
static int dotdot_missing(const char *arg, char *dotdot,
diff --git a/t/t7007-show.sh b/t/t7007-show.sh
index d6cc69e0f2cb..4eb824f2e39f 100755
--- a/t/t7007-show.sh
+++ b/t/t7007-show.sh
@@ -167,4 +167,28 @@ test_expect_success 'show --graph is forbidden' '
test_must_fail git show --graph HEAD
'
+test_expect_success 'show unmerged index' '
+ git reset --hard &&
+
+ git switch -C base &&
+ echo "base" > conflicting &&
+ git add conflicting &&
+ git commit -m "base" &&
+
+ git branch hello &&
+ git branch goodbye &&
+
+ git switch hello &&
+ echo "hello" > conflicting &&
+ git commit -am "hello" &&
+
+ git switch goodbye &&
+ echo "goodbye" > conflicting &&
+ git commit -am "goodbye" &&
+
+ git switch hello &&
+ test_must_fail git merge goodbye &&
+ git show --merge HEAD
+'
+
test_done
base-commit: 7014b55638da979331baf8dc31c4e1d697cf2d67
--
gitgitgadget
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH v2] revision: fix memory leak in prepare_show_merge()
2025-06-09 8:16 ` [PATCH v2] " Lidong Yan via GitGitGadget
@ 2025-06-09 20:48 ` Junio C Hamano
2025-06-10 0:37 ` [PATCH v3] " Lidong Yan via GitGitGadget
1 sibling, 0 replies; 12+ messages in thread
From: Junio C Hamano @ 2025-06-09 20:48 UTC (permalink / raw)
To: Lidong Yan via GitGitGadget; +Cc: git, Patrick Steinhardt, Lidong Yan
"Lidong Yan via GitGitGadget" <gitgitgadget@gmail.com> writes:
> +test_expect_success 'show unmerged index' '
> + git reset --hard &&
We use tabs for indent.
> +
> + git switch -C base &&
> + echo "base" > conflicting &&
Let's lose the SP between redirection operator ">" and its target
"conflicting", i.e.
echo "base" >conflicting &&
> + git add conflicting &&
> + git commit -m "base" &&
> +
> + git branch hello &&
> + git branch goodbye &&
> +
> + git switch hello &&
> + echo "hello" > conflicting &&
> + git commit -am "hello" &&
> +
> + git switch goodbye &&
> + echo "goodbye" > conflicting &&
> + git commit -am "goodbye" &&
> +
> + git switch hello &&
> + test_must_fail git merge goodbye &&
> + git show --merge HEAD
> +'
> +
> test_done
>
> base-commit: 7014b55638da979331baf8dc31c4e1d697cf2d67
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v3] revision: fix memory leak in prepare_show_merge()
2025-06-09 8:16 ` [PATCH v2] " Lidong Yan via GitGitGadget
2025-06-09 20:48 ` Junio C Hamano
@ 2025-06-10 0:37 ` Lidong Yan via GitGitGadget
1 sibling, 0 replies; 12+ messages in thread
From: Lidong Yan via GitGitGadget @ 2025-06-10 0:37 UTC (permalink / raw)
To: git; +Cc: Patrick Steinhardt, Lidong Yan, Lidong Yan
From: Lidong Yan <502024330056@smail.nju.edu.cn>
In revision.c:prepare_show_merge(), we allocated an array in prune
but forget to free it. Since parse_pathspec is not responsible to
free prune, we should add `free(prune)` in the end of prepare_show_merge().
Signed-off-by: Lidong Yan <502024330056@smail.nju.edu.cn>
---
revision: fix memory leak in prepare_show_merge()
In revision.c:prepare_show_merge(), we allocated an array in prune but
forget to free it. Since parse_pathspec is not responsible to free
prune, we should add free(prune) in the end of prepare_show_merge().
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1989%2Fbrandb97%2Ffix-revision-leak-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1989/brandb97/fix-revision-leak-v3
Pull-Request: https://github.com/git/git/pull/1989
Range-diff vs v2:
1: 61a2d98dad9 ! 1: 88795b33bbe revision: fix memory leak in prepare_show_merge()
@@ t/t7007-show.sh: test_expect_success 'show --graph is forbidden' '
'
+test_expect_success 'show unmerged index' '
-+ git reset --hard &&
++ git reset --hard &&
+
-+ git switch -C base &&
-+ echo "base" > conflicting &&
-+ git add conflicting &&
-+ git commit -m "base" &&
++ git switch -C base &&
++ echo "base" >conflicting &&
++ git add conflicting &&
++ git commit -m "base" &&
+
-+ git branch hello &&
-+ git branch goodbye &&
++ git branch hello &&
++ git branch goodbye &&
+
-+ git switch hello &&
-+ echo "hello" > conflicting &&
-+ git commit -am "hello" &&
++ git switch hello &&
++ echo "hello" >conflicting &&
++ git commit -am "hello" &&
+
-+ git switch goodbye &&
-+ echo "goodbye" > conflicting &&
-+ git commit -am "goodbye" &&
++ git switch goodbye &&
++ echo "goodbye" >conflicting &&
++ git commit -am "goodbye" &&
+
-+ git switch hello &&
-+ test_must_fail git merge goodbye &&
-+ git show --merge HEAD
++ git switch hello &&
++ test_must_fail git merge goodbye &&
++ git show --merge HEAD
+'
+
test_done
revision.c | 1 +
t/t7007-show.sh | 24 ++++++++++++++++++++++++
2 files changed, 25 insertions(+)
diff --git a/revision.c b/revision.c
index 2c36a9c179ef..afee11119615 100644
--- a/revision.c
+++ b/revision.c
@@ -2060,6 +2060,7 @@ static void prepare_show_merge(struct rev_info *revs)
parse_pathspec(&revs->prune_data, PATHSPEC_ALL_MAGIC & ~PATHSPEC_LITERAL,
PATHSPEC_PREFER_FULL | PATHSPEC_LITERAL_PATH, "", prune);
revs->limited = 1;
+ free(prune);
}
static int dotdot_missing(const char *arg, char *dotdot,
diff --git a/t/t7007-show.sh b/t/t7007-show.sh
index d6cc69e0f2cb..2d322b53d16e 100755
--- a/t/t7007-show.sh
+++ b/t/t7007-show.sh
@@ -167,4 +167,28 @@ test_expect_success 'show --graph is forbidden' '
test_must_fail git show --graph HEAD
'
+test_expect_success 'show unmerged index' '
+ git reset --hard &&
+
+ git switch -C base &&
+ echo "base" >conflicting &&
+ git add conflicting &&
+ git commit -m "base" &&
+
+ git branch hello &&
+ git branch goodbye &&
+
+ git switch hello &&
+ echo "hello" >conflicting &&
+ git commit -am "hello" &&
+
+ git switch goodbye &&
+ echo "goodbye" >conflicting &&
+ git commit -am "goodbye" &&
+
+ git switch hello &&
+ test_must_fail git merge goodbye &&
+ git show --merge HEAD
+'
+
test_done
base-commit: 7014b55638da979331baf8dc31c4e1d697cf2d67
--
gitgitgadget
^ permalink raw reply related [flat|nested] 12+ messages in thread
end of thread, other threads:[~2025-06-10 0:38 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-04 3:08 [PATCH] revision: fix memory leak in prepare_show_merge() Lidong Yan via GitGitGadget
2025-06-04 7:48 ` Patrick Steinhardt
2025-06-04 7:53 ` lidongyan
2025-06-04 8:06 ` Patrick Steinhardt
2025-06-04 10:25 ` lidongyan
2025-06-05 20:56 ` Junio C Hamano
2025-06-06 7:31 ` lidongyan
2025-06-06 16:47 ` Junio C Hamano
2025-06-09 3:10 ` lidongyan
2025-06-09 8:16 ` [PATCH v2] " Lidong Yan via GitGitGadget
2025-06-09 20:48 ` Junio C Hamano
2025-06-10 0:37 ` [PATCH v3] " Lidong Yan via GitGitGadget
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).