summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2006-11-13 15:19:22 +0100
committerJim Meyering <jim@meyering.net>2006-11-13 15:19:22 +0100
commit2061f0484753bb8de0fb9dd5821ee983ceda2e23 (patch)
treecc74dda2df1e94a9a5f90c779b0231aa5d2286d2
parentd5d00c7f9f2fc1bd43c1ef682e44117ff661ad01 (diff)
downloadcoreutils-2061f0484753bb8de0fb9dd5821ee983ceda2e23.tar.xz
Plug another technically-unimportant leak in sort.
* src/sort.c (main): Don't allocate memory for each new key here. (insertkey): Allocate memory for each key here, instead. (key_init): Rename from new_key. Don't allocate.
-rw-r--r--ChangeLog5
-rw-r--r--src/sort.c15
2 files changed, 14 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 33558767e..e737ee173 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2006-11-13 Jim Meyering <jim@meyering.net>
+ Plug another technically-unimportant leak in sort.
+ * src/sort.c (main): Don't allocate memory for each new key here.
+ (insertkey): Allocate memory for each key here, instead.
+ (key_init): Rename from new_key. Don't allocate.
+
* src/sort.c (main): Plug a tiny memory leak.
Move declaration of local "minus" down to be nearer point of use.
diff --git a/src/sort.c b/src/sort.c
index 56a0651eb..bdaf032a3 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -2099,13 +2099,15 @@ sort (char * const *files, size_t nfiles, char const *output_file)
}
}
-/* Insert key KEY at the end of the key list. */
+/* Insert a malloc'd copy of key KEY_ARG at the end of the key list. */
static void
-insertkey (struct keyfield *key)
+insertkey (struct keyfield *key_arg)
{
struct keyfield **p;
+ struct keyfield *key = xmalloc (sizeof *key);
+ *key = *key_arg;
for (p = &keylist; *p; p = &(*p)->next)
continue;
*p = key;
@@ -2271,9 +2273,9 @@ set_ordering (const char *s, struct keyfield *key, enum blanktype blanktype)
}
static struct keyfield *
-new_key (void)
+key_init (struct keyfield *key)
{
- struct keyfield *key = xzalloc (sizeof *key);
+ memset (key, 0, sizeof *key);
key->eword = SIZE_MAX;
return key;
}
@@ -2282,6 +2284,7 @@ int
main (int argc, char **argv)
{
struct keyfield *key;
+ struct keyfield key_buf;
struct keyfield gkey;
char const *s;
int c = 0;
@@ -2408,7 +2411,7 @@ main (int argc, char **argv)
{
/* Treat +POS1 [-POS2] as a key if possible; but silently
treat an operand as a file if it is not a valid +POS1. */
- key = new_key ();
+ key = key_init (&key_buf);
s = parse_field_count (optarg + 1, &key->sword, NULL);
if (s && *s == '.')
s = parse_field_count (s + 1, &key->schar, NULL);
@@ -2463,7 +2466,7 @@ main (int argc, char **argv)
break;
case 'k':
- key = new_key ();
+ key = key_init (&key_buf);
/* Get POS1. */
s = parse_field_count (optarg, &key->sword,