findutils-patches
[Top][All Lists]
Advanced

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

[Findutils-patches] [PATCH] find: fix minor memory leak in sharefile han


From: Bernhard Voelker
Subject: [Findutils-patches] [PATCH] find: fix minor memory leak in sharefile handling
Date: Fri, 30 Aug 2019 00:33:01 +0200

When sharefile_fopen fails to open the given file, e.g. due to the lack
of permissions, then the name of the file is not freed.

$ valgrind -v --leak-check=full find/find . -maxdepth 0 -fprint /
...
==28139== 2 bytes in 1 blocks are definitely lost in loss record 2 of 11
==28139==    at 0x483677F: malloc (in 
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==28139==    by 0x4923DBA: strdup (strdup.c:42)
==28139==    by 0x409E80: sharefile_fopen (sharefile.c:150)
==28139==    by 0x40CCA0: open_output_file (parser.c:3390)
==28139==    by 0x40CFA8: parse_fprint (parser.c:1010)
==28139==    by 0x408341: build_expression_tree (tree.c:1295)
==28139==    by 0x403AF7: main (ftsfind.c:712)

This memory leak is a trivial issue because find will terminate anyway
due to the error.

* find/sharefile.c (sharefile_open): Call entry_free instead of simple
free to also free the strdup-ed filename.
---
 find/sharefile.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/find/sharefile.c b/find/sharefile.c
index 02d25cc2..e82aec13 100644
--- a/find/sharefile.c
+++ b/find/sharefile.c
@@ -156,7 +156,7 @@ sharefile_fopen (sharefile_handle h, const char *filename)
 
   if (NULL == (new_entry->fp = fopen_safer (filename, p->mode)))
     {
-      free (new_entry);
+      entry_free (new_entry);
       return NULL;
     }
   else
-- 
2.22.1




reply via email to

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