diff options
author | Jim Meyering <jim@meyering.net> | 2001-10-18 07:42:11 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2001-10-18 07:42:11 +0000 |
commit | a7870f99972b3cb0a48f7d35651adac3ccc0ac0b (patch) | |
tree | fef9914cbc9c9920980589c072495dc16114ef7b /src | |
parent | 37af708d04aec3608cdf300563b58432bb11ac12 (diff) | |
download | coreutils-a7870f99972b3cb0a48f7d35651adac3ccc0ac0b.tar.xz |
(dest_info_free): New function.
(dest_info_init): Make the hash table code use it.
(record_dest): Store each DEST in malloc'd memory. Hence the above.
Use dest_info_free to free the `ent' we couldn't insert.
Diffstat (limited to 'src')
-rw-r--r-- | src/copy.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/copy.c b/src/copy.c index c3db53cf6..572d2a999 100644 --- a/src/copy.c +++ b/src/copy.c @@ -597,7 +597,7 @@ dest_info_hash (void const *x, unsigned int table_size) /* FIXME-maybe: is it worth the overhead of doing this just to avoid N^2 in such an unusual case? N would have to be very large to make the N^2 factor noticable, and - one would probably encounter a limit on the lenght of + one would probably encounter a limit on the length of a command line before it became a problem. */ unsigned int tmp = hash_pjw (p->name, table_size); @@ -614,13 +614,23 @@ dest_info_compare (void const *x, void const *y) return (SAME_INODE (*a, *b) && same_name (a->name, b->name)) ? true : false; } +/* Free a dest_info entry. */ +static void +dest_info_free (void *x) +{ + struct Dest_info *a = x; + free ((char *) (a->name)); + free (a); +} + /* Initialize the hash table implementing a set of dest_info entries. */ void dest_info_init () { dest_info = hash_initialize (DEST_INFO_INITIAL_CAPACITY, NULL, dest_info_hash, - dest_info_compare, free); + dest_info_compare, + dest_info_free); } /* Return nonzero if the file described by name, DEST, and DEST_STATS @@ -655,7 +665,7 @@ record_dest (char const *dest, struct stat const *dest_stats) return; ent = (struct Dest_info *) xmalloc (sizeof *ent); - ent->name = dest; + ent->name = xstrdup (dest); if (dest_stats) { ent->st_ino = dest_stats->st_ino; @@ -682,7 +692,7 @@ record_dest (char const *dest, struct stat const *dest_stats) { /* There was alread a matching entry in the table, so ENT was not inserted. Free it. */ - free (ent); + dest_info_free (ent); } } } |