From a7870f99972b3cb0a48f7d35651adac3ccc0ac0b Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 18 Oct 2001 07:42:11 +0000 Subject: (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. --- src/copy.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src') 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); } } } -- cgit v1.2.3-54-g00ecf