diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2010-08-10 20:25:20 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2010-08-10 20:25:56 -0700 |
commit | 9899e6cd853baf2704fdb52e55270ffbabd37dff (patch) | |
tree | 4e7d42c32ea90cb1409a7fb8c840dabbdca7dc04 /src/sort.c | |
parent | 2050a5913b0ee2e08de22db29340865f7f0ee608 (diff) | |
download | coreutils-9899e6cd853baf2704fdb52e55270ffbabd37dff.tar.xz |
sort, who: prefer free+malloc to realloc when contents are irrelevant
This change was prompted by the previous one: I audited the code
looking for similar examples. Too bad valgrind doesn't catch this.
* src/sort.c (check, mergefps): xrealloc -> free + xmalloc
* src/who.c (print_user): Likewise.
Diffstat (limited to 'src/sort.c')
-rw-r--r-- | src/sort.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/sort.c b/src/sort.c index 3dc7ae0b7..a8d0c142b 100644 --- a/src/sort.c +++ b/src/sort.c @@ -2767,7 +2767,8 @@ check (char const *file_name, char checkonly) } while (alloc < line->length); - temp.text = xrealloc (temp.text, alloc); + free (temp.text); + temp.text = xmalloc (alloc); } memcpy (temp.text, line->text, line->length); temp.length = line->length; @@ -2907,7 +2908,8 @@ mergefps (struct sortfile *files, size_t ntemps, size_t nfiles, } while ((savealloc *= 2) < smallest->length); - saved.text = xrealloc (saved.text, savealloc); + free (saved.text); + saved.text = xmalloc (savealloc); } saved.length = smallest->length; memcpy (saved.text, smallest->text, saved.length); |