]> git.ipfire.org Git - thirdparty/git.git/commitdiff
grep: fix leak in `grep_splice_or()`
authorPatrick Steinhardt <ps@pks.im>
Tue, 5 Nov 2024 06:16:50 +0000 (07:16 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 5 Nov 2024 06:37:52 +0000 (22:37 -0800)
In `grep_splice_or()` we search for the next `TRUE` node in our tree of
grep expressions and replace it with the given new expression. But we
don't free the old node, which causes a memory leak. Plug it.

This leak is exposed by t7810, but plugging it alone isn't sufficient to
make the test suite pass.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
grep.c

diff --git a/grep.c b/grep.c
index 701e58de04ef61d5c183200d96919cbc794f5d53..e9337f32cbf6e7afd426420e15d8828dc73ffb10 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -756,6 +756,7 @@ static struct grep_expr *grep_splice_or(struct grep_expr *x, struct grep_expr *y
                assert(x->node == GREP_NODE_OR);
                if (x->u.binary.right &&
                    x->u.binary.right->node == GREP_NODE_TRUE) {
+                       free(x->u.binary.right);
                        x->u.binary.right = y;
                        break;
                }