Blame SOURCES/coreutils-8.32-mem-leaks.patch

04161d
From be77b4ab7cb68fd2daf9de90bd75d844392788ac Mon Sep 17 00:00:00 2001
04161d
From: Kamil Dudka <kdudka@redhat.com>
04161d
Date: Thu, 25 Mar 2021 11:57:56 +0100
04161d
Subject: [PATCH 1/4] ln: fix memory leaks in do_link
04161d
04161d
* src/ln.c (do_link): Free memory allocated by convert_abs_rel
04161d
on all code paths (Bug#47373).
04161d
04161d
Upstream-commit: 6e98f67758260579d7d44ea5f2df4c82d28c9f58
04161d
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
04161d
---
04161d
 src/ln.c | 19 +++++++++++++------
04161d
 1 file changed, 13 insertions(+), 6 deletions(-)
04161d
04161d
diff --git a/src/ln.c b/src/ln.c
04161d
index ffa278e..9b52602 100644
04161d
--- a/src/ln.c
04161d
+++ b/src/ln.c
04161d
@@ -229,14 +229,14 @@ do_link (char const *source, int destdir_fd, char const *dest_base,
04161d
               if (errno != ENOENT)
04161d
                 {
04161d
                   error (0, errno, _("failed to access %s"), quoteaf (dest));
04161d
-                  return false;
04161d
+                  goto fail;
04161d
                 }
04161d
               force = false;
04161d
             }
04161d
           else if (S_ISDIR (dest_stats.st_mode))
04161d
             {
04161d
               error (0, 0, _("%s: cannot overwrite directory"), quotef (dest));
04161d
-              return false;
04161d
+              goto fail;
04161d
             }
04161d
           else if (seen_file (dest_set, dest, &dest_stats))
04161d
             {
04161d
@@ -245,7 +245,7 @@ do_link (char const *source, int destdir_fd, char const *dest_base,
04161d
               error (0, 0,
04161d
                      _("will not overwrite just-created %s with %s"),
04161d
                      quoteaf_n (0, dest), quoteaf_n (1, source));
04161d
-              return false;
04161d
+              goto fail;
04161d
             }
04161d
           else
04161d
             {
04161d
@@ -274,7 +274,7 @@ do_link (char const *source, int destdir_fd, char const *dest_base,
04161d
                     {
04161d
                       error (0, 0, _("%s and %s are the same file"),
04161d
                              quoteaf_n (0, source), quoteaf_n (1, dest));
04161d
-                      return false;
04161d
+                      goto fail;
04161d
                     }
04161d
                 }
04161d
 
04161d
@@ -285,7 +285,10 @@ do_link (char const *source, int destdir_fd, char const *dest_base,
04161d
                       fprintf (stderr, _("%s: replace %s? "),
04161d
                                program_name, quoteaf (dest));
04161d
                       if (!yesno ())
04161d
-                        return true;
04161d
+                        {
04161d
+                          free(rel_source);
04161d
+                          return true;
04161d
+                        }
04161d
                     }
04161d
 
04161d
                   if (backup_type != no_backups)
04161d
@@ -304,7 +307,7 @@ do_link (char const *source, int destdir_fd, char const *dest_base,
04161d
                            {
04161d
                               error (0, rename_errno, _("cannot backup %s"),
04161d
                                      quoteaf (dest));
04161d
-                              return false;
04161d
+                              goto fail;
04161d
                             }
04161d
                           force = false;
04161d
                         }
04161d
@@ -397,6 +400,10 @@ do_link (char const *source, int destdir_fd, char const *dest_base,
04161d
   free (backup_base);
04161d
   free (rel_source);
04161d
   return link_errno <= 0;
04161d
+
04161d
+fail:
04161d
+  free (rel_source);
04161d
+  return false;
04161d
 }
04161d
 
04161d
 void
04161d
-- 
04161d
2.26.3
04161d
04161d
04161d
From c051578e69bd8acf8f8a469566ae34e855345532 Mon Sep 17 00:00:00 2001
04161d
From: Paul Eggert <eggert@cs.ucla.edu>
04161d
Date: Thu, 25 Mar 2021 09:15:50 -0700
04161d
Subject: [PATCH 2/4] maint: indenting
04161d
04161d
* src/ln.c: Fix indenting.
04161d
04161d
Upstream-commit: 8980b7c898046d899646da01c296fd15f0cced21
04161d
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
04161d
---
04161d
 src/ln.c | 4 ++--
04161d
 1 file changed, 2 insertions(+), 2 deletions(-)
04161d
04161d
diff --git a/src/ln.c b/src/ln.c
04161d
index 9b52602..8881d6a 100644
04161d
--- a/src/ln.c
04161d
+++ b/src/ln.c
04161d
@@ -286,7 +286,7 @@ do_link (char const *source, int destdir_fd, char const *dest_base,
04161d
                                program_name, quoteaf (dest));
04161d
                       if (!yesno ())
04161d
                         {
04161d
-                          free(rel_source);
04161d
+                          free (rel_source);
04161d
                           return true;
04161d
                         }
04161d
                     }
04161d
@@ -304,7 +304,7 @@ do_link (char const *source, int destdir_fd, char const *dest_base,
04161d
                           free (backup_base);
04161d
                           backup_base = NULL;
04161d
                           if (rename_errno != ENOENT)
04161d
-                           {
04161d
+                            {
04161d
                               error (0, rename_errno, _("cannot backup %s"),
04161d
                                      quoteaf (dest));
04161d
                               goto fail;
04161d
-- 
04161d
2.26.3
04161d
04161d
04161d
From 0d6a4afe5bee0e397fb2fc3b205a29b32a69af9d Mon Sep 17 00:00:00 2001
04161d
From: Paul Eggert <eggert@cs.ucla.edu>
04161d
Date: Thu, 25 Mar 2021 09:16:36 -0700
04161d
Subject: [PATCH 3/4] hostname: use puts
04161d
04161d
* src/hostname.c (main): Prefer puts to printf "%s\n".
04161d
04161d
Upstream-commit: c7a588ac3632aae21642d4d568497177950d36bf
04161d
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
04161d
---
04161d
 src/hostname.c | 2 +-
04161d
 1 file changed, 1 insertion(+), 1 deletion(-)
04161d
04161d
diff --git a/src/hostname.c b/src/hostname.c
04161d
index 0b5c0cf..62cc98c 100644
04161d
--- a/src/hostname.c
04161d
+++ b/src/hostname.c
04161d
@@ -103,7 +103,7 @@ main (int argc, char **argv)
04161d
       hostname = xgethostname ();
04161d
       if (hostname == NULL)
04161d
         die (EXIT_FAILURE, errno, _("cannot determine hostname"));
04161d
-      printf ("%s\n", hostname);
04161d
+      puts (hostname);
04161d
     }
04161d
 
04161d
   if (optind + 1 < argc)
04161d
-- 
04161d
2.26.3
04161d
04161d
04161d
From 19c98d2080251edbaad9fb271aa10ad34f953500 Mon Sep 17 00:00:00 2001
04161d
From: Paul Eggert <eggert@cs.ucla.edu>
04161d
Date: Thu, 25 Mar 2021 11:20:18 -0700
04161d
Subject: [PATCH 4/4] hostname: pacify valgrind
04161d
04161d
* src/hostname.c (main) [IF_LINT]: Free hostname (Bug#47384).
04161d
04161d
Upstream-commit: 4698e284f37844bc9b9f63f00eb556ccaaed5030
04161d
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
04161d
---
04161d
 src/hostname.c | 1 +
04161d
 1 file changed, 1 insertion(+)
04161d
04161d
diff --git a/src/hostname.c b/src/hostname.c
04161d
index 62cc98c..7210248 100644
04161d
--- a/src/hostname.c
04161d
+++ b/src/hostname.c
04161d
@@ -104,6 +104,7 @@ main (int argc, char **argv)
04161d
       if (hostname == NULL)
04161d
         die (EXIT_FAILURE, errno, _("cannot determine hostname"));
04161d
       puts (hostname);
04161d
+      IF_LINT (free (hostname));
04161d
     }
04161d
 
04161d
   if (optind + 1 < argc)
04161d
-- 
04161d
2.26.3
04161d