From 1d3656a317815a46cfd5a89b33e843a32d4a47cc Mon Sep 17 00:00:00 2001 From: Laurent MONIN Date: Wed, 31 May 2006 19:33:36 +0200 Subject: [PATCH] Pass a pointer to a hash pointer to free_hash() to ensure hash pointer is NULL on return. --- src/bfu/style.c | 3 +-- src/bookmarks/bookmarks.c | 5 +---- src/document/html/renderer.c | 6 ++---- src/globhist/globhist.c | 3 +-- src/main/event.c | 4 ++-- src/mime/backend/mailcap.c | 3 +-- src/mime/backend/mimetypes.c | 3 +-- src/protocol/uri.c | 4 ++-- src/util/hash.c | 10 +++++----- src/util/hash.h | 2 +- 10 files changed, 17 insertions(+), 26 deletions(-) diff --git a/src/bfu/style.c b/src/bfu/style.c index f1a388926..8e8b5bda4 100644 --- a/src/bfu/style.c +++ b/src/bfu/style.c @@ -108,6 +108,5 @@ done_bfu_colors(void) mem_free_if(item->value); } - free_hash(bfu_colors); - bfu_colors = NULL; + free_hash(&bfu_colors); }; diff --git a/src/bookmarks/bookmarks.c b/src/bookmarks/bookmarks.c index a0f47d704..ef31bb7eb 100644 --- a/src/bookmarks/bookmarks.c +++ b/src/bookmarks/bookmarks.c @@ -162,10 +162,7 @@ free_bookmarks(struct list_head *bookmarks_list, free_list(*box_items); free_list(*bookmarks_list); - if (bookmark_cache) { - free_hash(bookmark_cache); - bookmark_cache = NULL; - } + if (bookmark_cache) free_hash(&bookmark_cache); } /* Does final cleanup and saving of bookmarks */ diff --git a/src/document/html/renderer.c b/src/document/html/renderer.c index d8c263d27..fb1dc99f0 100644 --- a/src/document/html/renderer.c +++ b/src/document/html/renderer.c @@ -1727,11 +1727,9 @@ free_table_cache(void) mem_free_if(item->value); } - free_hash(table_cache); + free_hash(&table_cache); + table_cache_entries = 0; } - - table_cache = NULL; - table_cache_entries = 0; } struct part * diff --git a/src/globhist/globhist.c b/src/globhist/globhist.c index 605a7ecf2..d7a162005 100644 --- a/src/globhist/globhist.c +++ b/src/globhist/globhist.c @@ -406,8 +406,7 @@ static void free_global_history(void) { if (globhist_cache) { - free_hash(globhist_cache); - globhist_cache = NULL; + free_hash(&globhist_cache); globhist_cache_entries = 0; } diff --git a/src/main/event.c b/src/main/event.c index ff8ab7e89..9153ca0ec 100644 --- a/src/main/event.c +++ b/src/main/event.c @@ -316,13 +316,13 @@ done_event(void) { int i; - if (event_hash) free_hash(event_hash); - for (i = 0; i < eventssize; i++) { mem_free_if(events[i].handlers); mem_free(events[i].name); } mem_free_set(&events, NULL); + + if (event_hash) free_hash(&event_hash); eventssize = 0; } diff --git a/src/mime/backend/mailcap.c b/src/mime/backend/mailcap.c index 00936148a..a0db45554 100644 --- a/src/mime/backend/mailcap.c +++ b/src/mime/backend/mailcap.c @@ -438,8 +438,7 @@ done_mailcap(struct module *module) mem_free(mitem); } - free_hash(mailcap_map); - mailcap_map = NULL; + free_hash(&mailcap_map); mailcap_map_size = 0; } diff --git a/src/mime/backend/mimetypes.c b/src/mime/backend/mimetypes.c index c7c73c27e..bb9cf95b9 100644 --- a/src/mime/backend/mimetypes.c +++ b/src/mime/backend/mimetypes.c @@ -207,8 +207,7 @@ done_mimetypes(struct module *module) } } - free_hash(mimetypes_map); - mimetypes_map = NULL; + free_hash(&mimetypes_map); mimetypes_map_size = 0; } diff --git a/src/protocol/uri.c b/src/protocol/uri.c index ca1a9eb8d..3642f3455 100644 --- a/src/protocol/uri.c +++ b/src/protocol/uri.c @@ -1526,7 +1526,7 @@ get_uri(unsigned char *string, enum uri_component components) entry = get_uri_cache_entry(string, strlen(string)); if (!entry) { if (!is_object_used(&uri_cache)) - free_hash(uri_cache.map); + free_hash(&uri_cache.map); return NULL; } @@ -1560,5 +1560,5 @@ done_uri(struct uri *uri) /* Last URI frees the cache */ object_unlock(&uri_cache); if (!is_object_used(&uri_cache)) - free_hash(uri_cache.map); + free_hash(&uri_cache.map); } diff --git a/src/util/hash.c b/src/util/hash.c index 42811e2d5..6d0036ad9 100644 --- a/src/util/hash.c +++ b/src/util/hash.c @@ -57,17 +57,17 @@ init_hash8(void) } void -free_hash(struct hash *hash) +free_hash(struct hash **hashp) { unsigned int i = 0; - assert(hash); + assert(hashp && *hashp); if_assert_failed return; - for (; i < hash_size(hash->width); i++) - free_list(hash->hash[i]); + for (; i < hash_size((*hashp)->width); i++) + free_list((*hashp)->hash[i]); - mem_free(hash); + mem_free_set(hashp, NULL); } diff --git a/src/util/hash.h b/src/util/hash.h index 93db7326d..d79da0a0d 100644 --- a/src/util/hash.h +++ b/src/util/hash.h @@ -25,7 +25,7 @@ struct hash { struct hash *init_hash8(void); -void free_hash(struct hash *hash); +void free_hash(struct hash **hashp); struct hash_item *add_hash_item(struct hash *hash, unsigned char *key, unsigned int keylen, void *value); struct hash_item *get_hash_item(struct hash *hash, unsigned char *key, unsigned int keylen);