summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-08-13 17:25:52 +0200
committerDavid Robillard <d@drobilla.net>2020-08-13 17:25:52 +0200
commita05b4c9bedfe99815eb887903e7687fe2d1bb3f9 (patch)
treec1523eec2092148b89625043016940cdefab17e5
parentadae13963a67d85d39ca990b262688a729a98edc (diff)
downloadzix-a05b4c9bedfe99815eb887903e7687fe2d1bb3f9.tar.gz
zix-a05b4c9bedfe99815eb887903e7687fe2d1bb3f9.tar.bz2
zix-a05b4c9bedfe99815eb887903e7687fe2d1bb3f9.zip
Make zix_hash_free() tolerate NULL
-rw-r--r--test/hash_test.c2
-rw-r--r--zix/hash.c4
2 files changed, 6 insertions, 0 deletions
diff --git a/test/hash_test.c b/test/hash_test.c
index 8b3e9de..ea808e6 100644
--- a/test/hash_test.c
+++ b/test/hash_test.c
@@ -202,6 +202,8 @@ stress(void)
int
main(void)
{
+ zix_hash_free(NULL);
+
if (stress()) {
return 1;
}
diff --git a/zix/hash.c b/zix/hash.c
index e8acfea..c4a2dba 100644
--- a/zix/hash.c
+++ b/zix/hash.c
@@ -75,6 +75,10 @@ zix_hash_new(ZixHashFunc hash_func,
ZIX_API void
zix_hash_free(ZixHash* hash)
{
+ if (!hash) {
+ return;
+ }
+
for (unsigned b = 0; b < *hash->n_buckets; ++b) {
ZixHashEntry* bucket = hash->buckets[b];
for (ZixHashEntry* e = bucket; e;) {