]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
sort: pacify -fsanitizer=leak
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 31 Jan 2022 16:42:07 +0000 (08:42 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 31 Jan 2022 20:07:39 +0000 (12:07 -0800)
* src/sort.c (pipe_fork, keycompare, sort, main):
Remove lint code that no longer seems to be needed.
(sort): Unconditionally compile ifdef lint code that is needed
to free storage even when not linting.
(main): Use main_exit, not return.

src/sort.c

index c55ca53698a3260b174a575fe53bd806d9ecd22c..1a3bda698b6340317427eb0c5e1ca8028524f08c 100644 (file)
@@ -1045,7 +1045,7 @@ pipe_fork (int pipefds[2], size_t tries)
   struct tempnode *saved_temphead;
   int saved_errno;
   double wait_retry = 0.25;
-  pid_t pid IF_LINT ( = -1);
+  pid_t pid;
   struct cs_status cs;
 
   if (pipe2 (pipefds, O_CLOEXEC) < 0)
@@ -2648,9 +2648,9 @@ keycompare (struct line const *a, struct line const *b)
           size_t tlena;
           size_t tlenb;
 
-          char enda IF_LINT (= 0);
-          char endb IF_LINT (= 0);
-          void *allocated IF_LINT (= NULL);
+          char enda;
+          char endb;
+          void *allocated;
           char stackbuf[4000];
 
           if (ignore || translate)
@@ -3995,7 +3995,6 @@ sort (char *const *files, size_t nfiles, char const *output_file,
       size_t nthreads)
 {
   struct buffer buf;
-  IF_LINT (buf.buf = NULL);
   size_t ntemps = 0;
   bool output_file_created = false;
 
@@ -4070,10 +4069,8 @@ sort (char *const *files, size_t nfiles, char const *output_file,
               sortlines (line, nthreads, buf.nlines, merge_tree + 1,
                          &queue, tfp, temp_output);
 
-#ifdef lint
               merge_tree_destroy (nthreads, merge_tree);
               queue_destroy (&queue);
-#endif
             }
           else
             write_unique (line - 1, tfp, temp_output);
@@ -4819,7 +4816,7 @@ main (int argc, char **argv)
 
       /* POSIX requires that sort return 1 IFF invoked with -c or -C and the
          input is not properly sorted.  */
-      return check (files[0], checkonly) ? EXIT_SUCCESS : SORT_OUT_OF_ORDER;
+      exit (check (files[0], checkonly) ? EXIT_SUCCESS : SORT_OUT_OF_ORDER);
     }
 
   /* Check all inputs are accessible, or exit immediately.  */
@@ -4836,7 +4833,6 @@ main (int argc, char **argv)
         sortfiles[i].name = files[i];
 
       merge (sortfiles, 0, nfiles, outfile);
-      IF_LINT (free (sortfiles));
     }
   else
     {
@@ -4853,15 +4849,8 @@ main (int argc, char **argv)
       sort (files, nfiles, outfile, nthreads);
     }
 
-#ifdef lint
-  if (files_from)
-    readtokens0_free (&tok);
-  else
-    free (files);
-#endif
-
   if (have_read_stdin && fclose (stdin) == EOF)
     sort_die (_("close failed"), "-");
 
-  return EXIT_SUCCESS;
+  main_exit (EXIT_SUCCESS);
 }