>From a4edebe5bafb8bf789cf5e9c807375c9bcdfab4e Mon Sep 17 00:00:00 2001 From: alireza <alirezaarzehga...@gmail.com> Date: Fri, 18 Nov 2022 01:33:10 +0330 Subject: [PATCH] yes: Remove memory leak on buf memory
Using `xmalloc` on an infinite loop due memory leak report on valgrind after termination. Replacing memory allocation from heap to using stack improves simplicity and correctness of the program. Signed-off-by: alireza <alirezaarzehga...@gmail.com> --- src/yes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/yes.c b/src/yes.c index 13b990e..28d129a 100644 --- a/src/yes.c +++ b/src/yes.c @@ -99,7 +99,7 @@ main (int argc, char **argv) /* Fill the buffer with one copy of the output. If possible, reuse the operands strings; this wins when the buffer would be large. */ - char *buf = reuse_operand_strings ? *operands : xmalloc (bufalloc); + char mem[bufalloc], *buf = reuse_operand_strings ? *operands : mem; size_t bufused = 0; operandp = operands; do -- 2.38.1