summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2001-11-03 08:23:54 +0000
committerJim Meyering <jim@meyering.net>2001-11-03 08:23:54 +0000
commit8cb947f70751eac06ffc29a31512bf9ea8332b65 (patch)
treec2b4f8e53cc0b4bac5a7b17666db5fb3a9bdb650 /lib
parent361446c55b5d23f70cde07888b0578663e3a3b69 (diff)
downloadcoreutils-8cb947f70751eac06ffc29a31512bf9ea8332b65.tar.xz
(hash_clear): Fix a bug that could lead to an infloop or
e.g., a fault due to an attempt to free a NULL pointer.
Diffstat (limited to 'lib')
-rw-r--r--lib/hash.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/hash.c b/lib/hash.c
index 8ba1344c9..1cf5c5ee3 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -1,5 +1,5 @@
/* hash - hashing table processing.
- Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
Written by Jim Meyering, 1992.
This program is free software; you can redistribute it and/or modify
@@ -576,19 +576,22 @@ void
hash_clear (Hash_table *table)
{
struct hash_entry *bucket;
- struct hash_entry *cursor;
for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
{
if (bucket->data)
{
+ struct hash_entry *cursor;
+ struct hash_entry *next;
+
/* Free the bucket overflow. */
- for (cursor = bucket->next; cursor; cursor = cursor->next)
+ for (cursor = bucket->next; cursor; cursor = next)
{
if (table->data_freer)
(*table->data_freer) (cursor->data);
cursor->data = NULL;
+ next = cursor->next;
/* Relinking is done one entry at a time, as it is to be expected
that overflows are either rare or short. */
cursor->next = table->free_entry_list;