]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: fix heap manipulations in previous commit
authorPádraig Brady <P@draigBrady.com>
Tue, 8 Sep 2015 11:53:11 +0000 (12:53 +0100)
committerPádraig Brady <P@draigBrady.com>
Tue, 8 Sep 2015 11:56:04 +0000 (12:56 +0100)
* src/sort.c (main): Ensure we don't free() and invalid
pointer when reading implicit stdin.  Also avoid
"definitely lost" valgrind warnings in the --files0-from case.

src/sort.c

index a7eda8325ac31235f07a9a94633591784642397f..7ce059282a0ccaedb5f3f7a29d6cc9438fbdd8d0 100644 (file)
@@ -4681,10 +4681,10 @@ main (int argc, char **argv)
 
   if (nfiles == 0)
     {
-      static char *minus = (char *) "-";
       nfiles = 1;
       free (files);
-      files = &minus;
+      files = xmalloc (sizeof *files);
+      *files = (char *) "-";
     }
 
   /* Need to re-check that we meet the minimum requirement for memory
@@ -4742,7 +4742,12 @@ main (int argc, char **argv)
       sort (files, nfiles, outfile, nthreads);
     }
 
-  IF_LINT (free (files));
+#ifdef lint
+  if (files_from)
+    readtokens0_free (&tok);
+  else
+    free (files);
+#endif
 
   if (have_read_stdin && fclose (stdin) == EOF)
     die (_("close failed"), "-");