Clean up isc_tlsctx_cache_detach()

For consistency with similar functions, rename `pcache` to `cachep`,
call a separate destroy function when references reach 0, and add
a missing call to isc_refcount_destroy().
This commit is contained in:
Evan Hunt 2022-01-04 13:02:44 -08:00
parent f5074c0c8e
commit 61c160c4a5
2 changed files with 23 additions and 18 deletions

View file

@ -240,13 +240,13 @@ isc_tlsctx_cache_attach(isc_tlsctx_cache_t *source,
*/
void
isc_tlsctx_cache_detach(isc_tlsctx_cache_t **pcache);
isc_tlsctx_cache_detach(isc_tlsctx_cache_t **cachep);
/*%<
* Remove a reference to the TLS context cache object.
*
* Requires:
*\li 'pcache' is a valid pointer to a pointer which must point to a
* valid TLS context cache object.
*\li 'cachep' is a pointer to a pointer to a valid TLS
* context cache object.
*/
isc_result_t

View file

@ -961,25 +961,15 @@ tlsctx_cache_entry_destroy(isc_mem_t *mctx, isc_tlsctx_cache_entry_t *entry) {
isc_mem_put(mctx, entry, sizeof(*entry));
}
void
isc_tlsctx_cache_detach(isc_tlsctx_cache_t **pcache) {
isc_tlsctx_cache_t *cache = NULL;
static void
tlsctx_cache_destroy(isc_tlsctx_cache_t *cache) {
isc_ht_iter_t *it = NULL;
isc_result_t result;
REQUIRE(pcache != NULL);
cache = *pcache;
*pcache = NULL;
REQUIRE(VALID_TLSCTX_CACHE(cache));
if (isc_refcount_decrement(&cache->references) > 1) {
return;
}
cache->magic = 0;
isc_refcount_destroy(&cache->references);
RUNTIME_CHECK(isc_ht_iter_create(cache->data, &it) == ISC_R_SUCCESS);
for (result = isc_ht_iter_first(it); result == ISC_R_SUCCESS;
result = isc_ht_iter_delcurrent_next(it))
@ -991,11 +981,26 @@ isc_tlsctx_cache_detach(isc_tlsctx_cache_t **pcache) {
isc_ht_iter_destroy(&it);
isc_ht_destroy(&cache->data);
isc_rwlock_destroy(&cache->rwlock);
isc_mem_putanddetach(&cache->mctx, cache, sizeof(*cache));
}
void
isc_tlsctx_cache_detach(isc_tlsctx_cache_t **cachep) {
isc_tlsctx_cache_t *cache = NULL;
REQUIRE(cachep != NULL);
cache = *cachep;
*cachep = NULL;
REQUIRE(VALID_TLSCTX_CACHE(cache));
if (isc_refcount_decrement(&cache->references) == 1) {
tlsctx_cache_destroy(cache);
}
}
isc_result_t
isc_tlsctx_cache_add(isc_tlsctx_cache_t *cache, const char *name,
const isc_tlsctx_cache_transport_t transport,