From ef86653d80692428af6bb75b4e01ea5d496423d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Mon, 4 Jul 2022 16:02:12 +0200 Subject: [PATCH 1/2] Add missing invocations of pthreads destructors Add isc_mutex_destroy() and isc_rwlock_destroy() calls missing from the commits that introduced the relevant isc_mutex_init() and isc_rwlock_init() calls: - 76bcb4d16b776e25cc67937f7d1a2fe6e365cfd7 - 15953043124416ab1dbc857f6885ecdb167401bb - 857f3bede37ccb419dac3816a0f96fa490af7d92 None of these omissions affect any hot paths, so they are not expected to cause operational issues; correctness is the only concern here. --- lib/dns/adb.c | 2 ++ lib/dns/resolver.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/lib/dns/adb.c b/lib/dns/adb.c index cb9539a778..95ca2d4070 100644 --- a/lib/dns/adb.c +++ b/lib/dns/adb.c @@ -2055,6 +2055,7 @@ destroy(dns_adb_t *adb) { dns_adbnamebucket_t *nbucket = NULL; isc_ht_iter_current(it, (void **)&nbucket); cleanup_names(nbucket, INT_MAX); + isc_mutex_destroy(&nbucket->lock); isc_mem_put(adb->mctx, nbucket, sizeof(*nbucket)); } isc_ht_iter_destroy(&it); @@ -2070,6 +2071,7 @@ destroy(dns_adb_t *adb) { dns_adbentrybucket_t *ebucket = NULL; isc_ht_iter_current(it, (void **)&ebucket); cleanup_entries(ebucket, INT_MAX); + isc_mutex_destroy(&ebucket->lock); isc_mem_put(adb->mctx, ebucket, sizeof(*ebucket)); } isc_ht_iter_destroy(&it); diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c index cd8ccd5f83..f6e976d37f 100644 --- a/lib/dns/resolver.c +++ b/lib/dns/resolver.c @@ -10094,6 +10094,7 @@ destroy(dns_resolver_t *res) { } isc_ht_iter_destroy(&it); isc_ht_destroy(&res->buckets); + isc_rwlock_destroy(&res->hash_lock); isc_ht_iter_create(res->zonebuckets, &it); for (result = isc_ht_iter_first(it); result == ISC_R_SUCCESS; @@ -10109,10 +10110,12 @@ destroy(dns_resolver_t *res) { ISC_LIST_UNLINK(bucket->list, fc, link); isc_mem_put(res->mctx, fc, sizeof(*fc)); } + isc_mutex_destroy(&bucket->lock); isc_mem_put(res->mctx, bucket, sizeof(*bucket)); } isc_ht_iter_destroy(&it); isc_ht_destroy(&res->zonebuckets); + isc_rwlock_destroy(&res->zonehash_lock); if (res->dispatches4 != NULL) { dns_dispatchset_destroy(&res->dispatches4); From 975a5a98cf16317423be751666c232d458053cbc Mon Sep 17 00:00:00 2001 From: Evan Hunt Date: Mon, 4 Jul 2022 16:02:12 +0200 Subject: [PATCH 2/2] Add missing isc_refcount_*() calls Commits 76bcb4d16b776e25cc67937f7d1a2fe6e365cfd7 and d48d8e1cf0879b818d710cc1238643610e386d38 did not include isc_refcount_destroy() calls that would be logical counterparts of the isc_refcount_init() calls these commits added. Add the missing isc_refcount_destroy() calls to destroy(). Adding these calls (which ensure a given structure's reference count equals 0 when it is destroyed, therefore detecting reference counting issues) uncovered another flaw in the commits mentioned above: missing isc_refcount_decrement() calls that would be logical counterparts of the isc_refcount_increment*() calls these commits added. Add the missing isc_refcount_decrement() calls to unlink_name() and unlink_entry(). --- lib/dns/adb.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/dns/adb.c b/lib/dns/adb.c index 95ca2d4070..98c25854df 100644 --- a/lib/dns/adb.c +++ b/lib/dns/adb.c @@ -871,6 +871,8 @@ unlink_name(dns_adbname_t *name) { } else { ISC_LIST_UNLINK(nbucket->names, name, plink); } + + isc_refcount_decrement(&nbucket->references); } /* @@ -944,6 +946,8 @@ unlink_entry(dns_adbentry_t *entry) { } else { ISC_LIST_UNLINK(ebucket->entries, entry, plink); } + + isc_refcount_decrement(&ebucket->references); } static void @@ -2056,6 +2060,7 @@ destroy(dns_adb_t *adb) { isc_ht_iter_current(it, (void **)&nbucket); cleanup_names(nbucket, INT_MAX); isc_mutex_destroy(&nbucket->lock); + isc_refcount_destroy(&nbucket->references); isc_mem_put(adb->mctx, nbucket, sizeof(*nbucket)); } isc_ht_iter_destroy(&it); @@ -2072,6 +2077,7 @@ destroy(dns_adb_t *adb) { isc_ht_iter_current(it, (void **)&ebucket); cleanup_entries(ebucket, INT_MAX); isc_mutex_destroy(&ebucket->lock); + isc_refcount_destroy(&ebucket->references); isc_mem_put(adb->mctx, ebucket, sizeof(*ebucket)); } isc_ht_iter_destroy(&it); @@ -2080,6 +2086,7 @@ destroy(dns_adb_t *adb) { isc_rwlock_destroy(&adb->entries_lock); isc_mutex_destroy(&adb->lock); + isc_refcount_destroy(&adb->references); isc_task_detach(&adb->task); isc_stats_detach(&adb->stats);