summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2007-02-23 15:18:16 +0100
committerJim Meyering <jim@meyering.net>2007-02-23 15:18:16 +0100
commitcb121d8f3683e81cf51c8f0c7a28dfa58ae68fa8 (patch)
tree211be79c1a1135f705555d4ef5fecb7028da8523 /src
parent3a9070dce7e3722c050c3e2793dd14e2e6a05d67 (diff)
downloadcoreutils-cb121d8f3683e81cf51c8f0c7a28dfa58ae68fa8.tar.xz
With -Dlint, make shuf free all heap-allocated storage.
* src/shuf.c (main): Move declaration of input_lines to function scope, and initialize to NULL, so we can free it. [lint]: Free all malloc'd memory. * tests/misc/shuf: Also test shuf's -e and -i options.
Diffstat (limited to 'src')
-rw-r--r--src/shuf.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/shuf.c b/src/shuf.c
index 68003c259..bfc9f30a2 100644
--- a/src/shuf.c
+++ b/src/shuf.c
@@ -1,6 +1,6 @@
/* Shuffle lines of text.
- Copyright (C) 2006 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2007 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -251,6 +251,7 @@ main (int argc, char **argv)
char const *outfile = NULL;
char *random_source = NULL;
char eolbyte = '\n';
+ char **input_lines = NULL;
int optc;
int n_operands;
@@ -258,7 +259,7 @@ main (int argc, char **argv)
size_t n_lines;
char **line;
struct randint_source *randint_source;
- size_t const *permutation;
+ size_t *permutation;
initialize_main (&argc, &argv);
program_name = argv[0];
@@ -366,8 +367,6 @@ main (int argc, char **argv)
}
else
{
- char **input_lines;
-
switch (n_operands)
{
case 0:
@@ -408,5 +407,15 @@ main (int argc, char **argv)
if (write_permuted_output (head_lines, line, lo_input, permutation) != 0)
error (EXIT_FAILURE, errno, _("write error"));
+#ifdef lint
+ free (permutation);
+ randint_all_free (randint_source);
+ if (input_lines)
+ {
+ free (input_lines[0]);
+ free (input_lines);
+ }
+#endif
+
return EXIT_SUCCESS;
}