coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] yes: Remove memory leak on buf memory


From: Alireza Arzehgar
Subject: [PATCH] yes: Remove memory leak on buf memory
Date: Fri, 18 Nov 2022 01:51:38 +0330

>From a4edebe5bafb8bf789cf5e9c807375c9bcdfab4e Mon Sep 17 00:00:00 2001
From: alireza <alirezaarzehgar82@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 <alirezaarzehgar82@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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]