GNU bug report logs - #72446
[PATCH] stat: Fix memleak

Previous Next

Package: coreutils;

Reported by: Dmitry Chestnykh <dm.chestnykh <at> gmail.com>

Date: Sat, 3 Aug 2024 17:24:02 UTC

Severity: normal

Tags: notabug, patch

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

Full log


Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Chestnykh <dm.chestnykh <at> gmail.com>
To: bug-coreutils <at> gnu.org
Cc: Dmitry Chestnykh <dm.chestnykh <at> gmail.com>
Subject: [PATCH] stat: Fix memleak
Date: Sat,  3 Aug 2024 19:10:28 +0300
format and format2 strings are allocated
by `malloc()` inside `xasprintf` so the memory
should be freed

* src/stat.c: Call `free()` on `format` and `format2`
---
 src/stat.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/stat.c b/src/stat.c
index 1513abfaa..47f3b5052 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -1974,5 +1974,7 @@ main (int argc, char *argv[])
            ? do_statfs (argv[i], format)
            : do_stat (argv[i], format, format2));
 
+  free(format);
+  free(format2);
   main_exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
 }
-- 
2.46.0





This bug report was last modified 290 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.