9ad78c90c77636b5491f63470ed241123ca85cf6 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. From 9ad78c90c77636b5491f63470ed241123ca85cf6 Mon Sep 17 00:00:00 2001
  2. From: Bernhard Voelker <mail@bernhard-voelker.de>
  3. Date: Thu, 29 Aug 2019 08:36:26 +0200
  4. Subject: find: fix minor memory leak in sharefile handling
  5. When sharefile_fopen fails to open the given file, e.g. due to the lack
  6. of permissions, then the name of the file is not freed.
  7. $ valgrind -v --leak-check=full find/find . -maxdepth 0 -fprint /
  8. ...
  9. ==28139== 2 bytes in 1 blocks are definitely lost in loss record 2 of 11
  10. ==28139== at 0x483677F: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
  11. ==28139== by 0x4923DBA: strdup (strdup.c:42)
  12. ==28139== by 0x409E80: sharefile_fopen (sharefile.c:150)
  13. ==28139== by 0x40CCA0: open_output_file (parser.c:3390)
  14. ==28139== by 0x40CFA8: parse_fprint (parser.c:1010)
  15. ==28139== by 0x408341: build_expression_tree (tree.c:1295)
  16. ==28139== by 0x403AF7: main (ftsfind.c:712)
  17. This memory leak is a trivial issue because find will terminate anyway
  18. due to the error.
  19. * find/sharefile.c (sharefile_open): Call entry_free instead of simple
  20. free to also free the strdup-ed filename.
  21. ---
  22. find/sharefile.c | 2 +-
  23. 1 file changed, 1 insertion(+), 1 deletion(-)
  24. diff --git a/find/sharefile.c b/find/sharefile.c
  25. index 02d25cc..e82aec1 100644
  26. --- a/find/sharefile.c
  27. +++ b/find/sharefile.c
  28. @@ -156,7 +156,7 @@ sharefile_fopen (sharefile_handle h, const char *filename)
  29. if (NULL == (new_entry->fp = fopen_safer (filename, p->mode)))
  30. {
  31. - free (new_entry);
  32. + entry_free (new_entry);
  33. return NULL;
  34. }
  35. else
  36. --
  37. cgit v1.0-41-gc330