diff mbox series

[v2,03/22] grep: fix leak in `grep_splice_or()`

Message ID cb4eee37b4024a451a385f94ad57e7278e542de7.1729502824.git.ps@pks.im (mailing list archive)
State Superseded
Headers show
Series Memory leak fixes (pt.9) | expand

Commit Message

Patrick Steinhardt Oct. 21, 2024, 9:28 a.m. UTC
In `grep_splice_or()` we search for the next `TRUE` node in our tree of
grep exrpessions 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>
---
 grep.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Kristoffer Haugsbakk Oct. 21, 2024, 9:42 a.m. UTC | #1
On Mon, Oct 21, 2024, at 11:28, Patrick Steinhardt wrote:
> In `grep_splice_or()` we search for the next `TRUE` node in our tree of
> grep exrpessions and replace it with the given new expression. But we

s/exrpessions/expressions/
diff mbox series

Patch

diff --git a/grep.c b/grep.c
index 701e58de04e..e9337f32cbf 100644
--- 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;
 		}