2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-22 10:10:06 +00:00

Clear the pointer to destroyed object early using the semantic patch

Also disable the semantic patch as the code needs tweaks here and there because
some destroy functions might not destroy the object and return early if the
object is still in use.
This commit is contained in:
Ondřej Surý 2020-02-08 04:37:54 -08:00
parent b97d003033
commit bc1d4c9cb4
64 changed files with 94 additions and 144 deletions

View File

@ -574,6 +574,7 @@ match_keyset_dsset(dns_rdataset_t *keyset, dns_rdataset_t *dsset,
static void
free_keytable(keyinfo_t **keytable_p) {
keyinfo_t *keytable = *keytable_p;
*keytable_p = NULL;
keyinfo_t *ki;
int i;
@ -585,7 +586,6 @@ free_keytable(keyinfo_t **keytable_p) {
}
isc_mem_put(mctx, keytable, sizeof(keyinfo_t) * nkey);
*keytable_p = NULL;
}
/*

View File

@ -1477,10 +1477,10 @@ named_controls_create(named_server_t *server, named_controls_t **ctrlsp) {
void
named_controls_destroy(named_controls_t **ctrlsp) {
named_controls_t *controls = *ctrlsp;
*ctrlsp = NULL;
REQUIRE(ISC_LIST_EMPTY(controls->listeners));
isccc_symtab_destroy(&controls->symtab);
isc_mem_put(controls->server->mctx, controls, sizeof(*controls));
*ctrlsp = NULL;
}

View File

@ -313,6 +313,7 @@ check_result(isc_result_t result, const char *msg) {
static char *
nsu_strsep(char **stringp, const char *delim) {
char *string = *stringp;
*stringp = NULL;
char *s;
const char *d;
char sc, dc;
@ -340,7 +341,6 @@ nsu_strsep(char **stringp, const char *delim) {
}
}
}
*stringp = NULL;
return (string);
}

View File

@ -178,6 +178,7 @@ destroy_sample_instance(sample_instance_t **instp) {
REQUIRE(instp != NULL);
inst = *instp;
*instp = NULL;
if (inst == NULL)
return;
@ -195,6 +196,4 @@ destroy_sample_instance(sample_instance_t **instp) {
isc_task_detach(&inst->task);
MEM_PUT_AND_DETACH(inst);
*instp = NULL;
}

View File

@ -2293,8 +2293,8 @@ check_expire_name(dns_adbname_t **namep, isc_stdtime_t now) {
/*
* The name is empty. Delete it.
*/
result = kill_name(&name, DNS_EVENT_ADBEXPIRED);
*namep = NULL;
result = kill_name(&name, DNS_EVENT_ADBEXPIRED);
/*
* Our caller, or one of its callers, will be calling check_exit() at
@ -2379,13 +2379,13 @@ check_expire_entry(dns_adb_t *adb, dns_adbentry_t **entryp, isc_stdtime_t now)
/*
* The entry is not in use. Delete it.
*/
*entryp = NULL;
DP(DEF_LEVEL, "killing entry %p", entry);
INSIST(ISC_LINK_LINKED(entry, plink));
result = unlink_entry(adb, entry);
free_adbentry(adb, &entry);
if (result)
dec_adb_irefcnt(adb);
*entryp = NULL;
return (result);
}
@ -4604,11 +4604,11 @@ dns_adb_freeaddrinfo(dns_adb_t *adb, dns_adbaddrinfo_t **addrp) {
REQUIRE(DNS_ADB_VALID(adb));
REQUIRE(addrp != NULL);
addr = *addrp;
*addrp = NULL;
REQUIRE(DNS_ADBADDRINFO_VALID(addr));
entry = addr->entry;
REQUIRE(DNS_ADBENTRY_VALID(entry));
*addrp = NULL;
overmem = isc_mem_isovermem(adb->mctx);
bucket = addr->entry->lock_bucket;

View File

@ -91,6 +91,7 @@ dns_badcache_destroy(dns_badcache_t **bcp) {
REQUIRE(bcp != NULL && *bcp != NULL);
bc = *bcp;
*bcp = NULL;
dns_badcache_flush(bc);
@ -98,7 +99,6 @@ dns_badcache_destroy(dns_badcache_t **bcp) {
isc_mutex_destroy(&bc->lock);
isc_mem_put(bc->mctx, bc->table, sizeof(dns_bcentry_t *) * bc->size);
isc_mem_putanddetach(&bc->mctx, bc, sizeof(dns_badcache_t));
*bcp = NULL;
}
static isc_result_t

View File

@ -266,6 +266,7 @@ dns_byaddr_destroy(dns_byaddr_t **byaddrp) {
REQUIRE(byaddrp != NULL);
byaddr = *byaddrp;
*byaddrp = NULL;
REQUIRE(VALID_BYADDR(byaddr));
REQUIRE(byaddr->event == NULL);
REQUIRE(byaddr->task == NULL);
@ -274,6 +275,4 @@ dns_byaddr_destroy(dns_byaddr_t **byaddrp) {
isc_mutex_destroy(&byaddr->lock);
byaddr->magic = 0;
isc_mem_putanddetach(&byaddr->mctx, byaddr, sizeof(*byaddr));
*byaddrp = NULL;
}

View File

@ -404,8 +404,8 @@ dns_cache_detach(dns_cache_t **cachep) {
REQUIRE(cachep != NULL);
cache = *cachep;
REQUIRE(VALID_CACHE(cache));
*cachep = NULL;
REQUIRE(VALID_CACHE(cache));
if (isc_refcount_decrement(&cache->references) == 1) {
cache->cleaner.overmem = false;

View File

@ -264,9 +264,8 @@ dns_catz_entry_detach(dns_catz_zone_t *zone, dns_catz_entry_t **entryp) {
REQUIRE(DNS_CATZ_ZONE_VALID(zone));
REQUIRE(entryp != NULL);
entry = *entryp;
REQUIRE(DNS_CATZ_ENTRY_VALID(entry));
*entryp = NULL;
REQUIRE(DNS_CATZ_ENTRY_VALID(entry));
if (isc_refcount_decrement(&entry->refs) == 1) {
isc_mem_t *mctx = zone->catzs->mctx;

View File

@ -734,14 +734,13 @@ putrdataset(isc_mem_t *mctx, dns_rdataset_t **rdatasetp) {
REQUIRE(rdatasetp != NULL);
rdataset = *rdatasetp;
*rdatasetp = NULL;
REQUIRE(rdataset != NULL);
if (dns_rdataset_isassociated(rdataset))
dns_rdataset_disassociate(rdataset);
isc_mem_put(mctx, rdataset, sizeof(*rdataset));
*rdatasetp = NULL;
}
static void

View File

@ -124,8 +124,8 @@ dns_dbtable_detach(dns_dbtable_t **dbtablep) {
REQUIRE(dbtablep != NULL);
dbtable = *dbtablep;
REQUIRE(VALID_DBTABLE(dbtable));
*dbtablep = NULL;
REQUIRE(VALID_DBTABLE(dbtable));
if (isc_refcount_decrement(&dbtable->references) == 1) {
dbtable_free(dbtable);

View File

@ -104,6 +104,7 @@ dns_difftuple_create(isc_mem_t *mctx,
void
dns_difftuple_free(dns_difftuple_t **tp) {
dns_difftuple_t *t = *tp;
*tp = NULL;
isc_mem_t *mctx;
REQUIRE(DNS_DIFFTUPLE_VALID(t));
@ -113,7 +114,6 @@ dns_difftuple_free(dns_difftuple_t **tp) {
mctx = t->mctx;
isc_mem_free(mctx, t);
isc_mem_detach(&mctx);
*tp = NULL;
}
isc_result_t

View File

@ -594,8 +594,9 @@ new_portentry(dns_dispatch_t *disp, in_port_t port) {
*/
static void
deref_portentry(dns_dispatch_t *disp, dispportentry_t **portentryp) {
dispportentry_t *portentry = *portentryp;
dns_qid_t *qid;
dispportentry_t *portentry = *portentryp;
*portentryp = NULL;
REQUIRE(disp->port_table != NULL);
REQUIRE(portentry != NULL);
@ -609,13 +610,6 @@ deref_portentry(dns_dispatch_t *disp, dispportentry_t **portentryp) {
isc_mempool_put(disp->portpool, portentry);
UNLOCK(&qid->lock);
}
/*
* XXXWPK TODO: is it really necessary?
* Set '*portentryp' to NULL inside the lock so that
* dispsock->portentry does not change in socket_search.
*/
*portentryp = NULL;
}
/*%
@ -785,6 +779,7 @@ destroy_dispsocket(dns_dispatch_t *disp, dispsocket_t **dispsockp) {
REQUIRE(dispsockp != NULL && *dispsockp != NULL);
dispsock = *dispsockp;
*dispsockp = NULL;
REQUIRE(!ISC_LINK_LINKED(dispsock, link));
disp->nsockets--;
@ -803,8 +798,6 @@ destroy_dispsocket(dns_dispatch_t *disp, dispsocket_t **dispsockp) {
if (dispsock->task != NULL)
isc_task_detach(&dispsock->task);
isc_mempool_put(disp->mgr->spool, dispsock);
*dispsockp = NULL;
}
/*%
@ -2237,10 +2230,10 @@ qid_destroy(isc_mem_t *mctx, dns_qid_t **qidp) {
REQUIRE(qidp != NULL);
qid = *qidp;
*qidp = NULL;
REQUIRE(VALID_QID(qid));
*qidp = NULL;
qid->magic = 0;
isc_mem_put(mctx, qid->qid_table,
qid->qid_nbuckets * sizeof(dns_displist_t));
@ -3632,14 +3625,13 @@ dns_dispatchset_destroy(dns_dispatchset_t **dsetp) {
REQUIRE(dsetp != NULL && *dsetp != NULL);
dset = *dsetp;
*dsetp = NULL;
for (i = 0; i < dset->ndisp; i++)
dns_dispatch_detach(&(dset->dispatches[i]));
isc_mem_put(dset->mctx, dset->dispatches,
sizeof(dns_dispatch_t *) * dset->ndisp);
isc_mutex_destroy(&dset->lock);
isc_mem_putanddetach(&dset->mctx, dset, sizeof(dns_dispatchset_t));
*dsetp = NULL;
}
void

View File

@ -798,13 +798,13 @@ rpsdb_rdatasetiter_destroy(dns_rdatasetiter_t **iteratorp) {
isc_mem_t *mctx;
iterator = *iteratorp;
*iteratorp = NULL;
rpsdb = (rpsdb_t *)iterator->db;
REQUIRE(VALID_RPSDB(rpsdb));
mctx = iterator->db->mctx;
dns_db_detachnode(iterator->db, &iterator->node);
isc_mem_put(mctx, iterator, sizeof(rpsdb_rdatasetiter_t));
*iteratorp = NULL;
}
static isc_result_t

View File

@ -1285,10 +1285,10 @@ dns_dnsseckey_destroy(isc_mem_t *mctx, dns_dnsseckey_t **dkp) {
REQUIRE(dkp != NULL && *dkp != NULL);
dk = *dkp;
*dkp = NULL;
if (dk->key != NULL)
dst_key_free(&dk->key);
isc_mem_put(mctx, dk, sizeof(dns_dnsseckey_t));
*dkp = NULL;
}
void

View File

@ -1334,6 +1334,7 @@ dns_dtdata_free(dns_dtdata_t **dp) {
REQUIRE(dp != NULL && *dp != NULL);
d = *dp;
*dp = NULL;
if (d->msg != NULL)
dns_message_destroy(&d->msg);
@ -1341,6 +1342,4 @@ dns_dtdata_free(dns_dtdata_t **dp) {
dnstap__dnstap__free_unpacked(d->frame, NULL);
isc_mem_putanddetach(&d->mctx, d, sizeof(*d));
*dp = NULL;
}

View File

@ -353,13 +353,13 @@ dst_context_destroy(dst_context_t **dctxp) {
REQUIRE(dctxp != NULL && VALID_CTX(*dctxp));
dctx = *dctxp;
*dctxp = NULL;
INSIST(dctx->key->func->destroyctx != NULL);
dctx->key->func->destroyctx(dctx);
if (dctx->key != NULL)
dst_key_free(&dctx->key);
dctx->magic = 0;
isc_mem_putanddetach(&dctx->mctx, dctx, sizeof(dst_context_t));
*dctxp = NULL;
}
isc_result_t

View File

@ -198,11 +198,10 @@ unload_library(dyndb_implementation_t **impp) {
REQUIRE(impp != NULL && *impp != NULL);
imp = *impp;
*impp = NULL;
isc_mem_free(imp->mctx, imp->name);
isc_mem_putanddetach(&imp->mctx, imp, sizeof(dyndb_implementation_t));
*impp = NULL;
}
#elif _WIN32
static isc_result_t
@ -310,11 +309,10 @@ unload_library(dyndb_implementation_t **impp) {
REQUIRE(impp != NULL && *impp != NULL);
imp = *impp;
*impp = NULL;
isc_mem_free(imp->mctx, imp->name);
isc_mem_putanddetach(&imp->mctx, imp, sizeof(dyndb_implementation_t));
*impp = NULL;
}
#else /* HAVE_DLFCN_H || _WIN32 */
static isc_result_t

View File

@ -201,14 +201,13 @@ dns_fwdtable_destroy(dns_fwdtable_t **fwdtablep) {
REQUIRE(fwdtablep != NULL && VALID_FWDTABLE(*fwdtablep));
fwdtable = *fwdtablep;
*fwdtablep = NULL;
dns_rbt_destroy(&fwdtable->table);
isc_rwlock_destroy(&fwdtable->rwlock);
fwdtable->magic = 0;
isc_mem_putanddetach(&fwdtable->mctx, fwdtable, sizeof(dns_fwdtable_t));
*fwdtablep = NULL;
}
/***

View File

@ -1233,6 +1233,7 @@ dns_journal_write_transaction(dns_journal_t *j, dns_diff_t *diff) {
void
dns_journal_destroy(dns_journal_t **journalp) {
dns_journal_t *j = *journalp;
*journalp = NULL;
REQUIRE(DNS_JOURNAL_VALID(j));
j->it.result = ISC_R_FAILURE;
@ -1254,7 +1255,6 @@ dns_journal_destroy(dns_journal_t **journalp) {
(void)isc_stdio_close(j->fp);
j->magic = 0;
isc_mem_putanddetach(&j->mctx, j, sizeof(*j));
*journalp = NULL;
}
/*

View File

@ -416,6 +416,7 @@ dns_lookup_destroy(dns_lookup_t **lookupp) {
REQUIRE(lookupp != NULL);
lookup = *lookupp;
*lookupp = NULL;
REQUIRE(VALID_LOOKUP(lookup));
REQUIRE(lookup->event == NULL);
REQUIRE(lookup->task == NULL);
@ -428,6 +429,4 @@ dns_lookup_destroy(dns_lookup_t **lookupp) {
isc_mutex_destroy(&lookup->lock);
lookup->magic = 0;
isc_mem_putanddetach(&lookup->mctx, lookup, sizeof(*lookup));
*lookupp = NULL;
}

View File

@ -404,9 +404,8 @@ dns_loadctx_detach(dns_loadctx_t **lctxp) {
REQUIRE(lctxp != NULL);
lctx = *lctxp;
REQUIRE(DNS_LCTX_VALID(lctx));
*lctxp = NULL;
REQUIRE(DNS_LCTX_VALID(lctx));
if (isc_refcount_decrement(&lctx->references) == 1) {
loadctx_destroy(lctx);

View File

@ -1317,9 +1317,8 @@ dns_dumpctx_detach(dns_dumpctx_t **dctxp) {
REQUIRE(dctxp != NULL);
dctx = *dctxp;
REQUIRE(DNS_DCTX_VALID(dctx));
*dctxp = NULL;
REQUIRE(DNS_DCTX_VALID(dctx));
if (isc_refcount_decrement(&dctx->references) == 1) {
dumpctx_destroy(dctx);

View File

@ -2555,10 +2555,10 @@ dns_message_puttempname(dns_message_t *msg, dns_name_t **itemp) {
REQUIRE(DNS_MESSAGE_VALID(msg));
REQUIRE(itemp != NULL && *itemp != NULL);
item = *itemp;
*itemp = NULL;
REQUIRE(!ISC_LINK_LINKED(item, link));
REQUIRE(ISC_LIST_HEAD(item->list) == NULL);
*itemp = NULL;
if (dns_name_dynamic(item))
dns_name_free(item, msg->mctx);
isc_mempool_put(msg->namepool, item);

View File

@ -106,6 +106,7 @@ peerlist_delete(dns_peerlist_t **list) {
REQUIRE(DNS_PEERLIST_VALID(*list));
l = *list;
*list = NULL;
isc_refcount_destroy(&l->refs);
@ -119,8 +120,6 @@ peerlist_delete(dns_peerlist_t **list) {
l->magic = 0;
isc_mem_put(l->mem, l, sizeof(*l));
*list = NULL;
}
void
@ -270,6 +269,7 @@ peer_delete(dns_peer_t **peer) {
REQUIRE(DNS_PEER_VALID(*peer));
p = *peer;
*peer = NULL;
isc_refcount_destroy(&p->refs);
@ -293,8 +293,6 @@ peer_delete(dns_peer_t **peer) {
sizeof(*p->transfer_source));
isc_mem_put(mem, p, sizeof(*p));
*peer = NULL;
}
isc_result_t

View File

@ -1000,6 +1000,8 @@ dns_rbt_destroy2(dns_rbt_t **rbtp, unsigned int quantum) {
if (rbt->root != NULL)
return (ISC_R_QUOTA);
*rbtp = NULL;
INSIST(rbt->nodecount == 0);
rbt->mmap_location = NULL;
@ -1011,7 +1013,6 @@ dns_rbt_destroy2(dns_rbt_t **rbtp, unsigned int quantum) {
rbt->magic = 0;
isc_mem_putanddetach(&rbt->mctx, rbt, sizeof(*rbt));
*rbtp = NULL;
return (ISC_R_SUCCESS);
}
@ -2768,11 +2769,11 @@ deletefromlevel(dns_rbtnode_t *item, dns_rbtnode_t **rootp) {
static void
freenode(dns_rbt_t *rbt, dns_rbtnode_t **nodep) {
dns_rbtnode_t *node = *nodep;
*nodep = NULL;
if (node->is_mmapped == 0) {
isc_mem_put(rbt->mctx, node, NODE_SIZE(node));
}
*nodep = NULL;
rbt->nodecount--;
}

View File

@ -283,9 +283,9 @@ requestmgr_detach(dns_requestmgr_t **requestmgrp) {
REQUIRE(requestmgrp != NULL);
requestmgr = *requestmgrp;
*requestmgrp = NULL;
REQUIRE(VALID_REQUESTMGR(requestmgr));
*requestmgrp = NULL;
LOCK(&requestmgr->lock);
INSIST(requestmgr->iref > 0);
requestmgr->iref--;
@ -328,6 +328,7 @@ dns_requestmgr_detach(dns_requestmgr_t **requestmgrp) {
REQUIRE(requestmgrp != NULL);
requestmgr = *requestmgrp;
*requestmgrp = NULL;
REQUIRE(VALID_REQUESTMGR(requestmgr));
LOCK(&requestmgr->lock);
@ -346,8 +347,6 @@ dns_requestmgr_detach(dns_requestmgr_t **requestmgrp) {
if (need_destroy)
mgr_destroy(requestmgr);
*requestmgrp = NULL;
}
static void
@ -1202,6 +1201,7 @@ dns_request_destroy(dns_request_t **requestp) {
REQUIRE(requestp != NULL && VALID_REQUEST(*requestp));
request = *requestp;
*requestp = NULL;
req_log(ISC_LOG_DEBUG(3), "dns_request_destroy: request %p", request);
@ -1223,8 +1223,6 @@ dns_request_destroy(dns_request_t **requestp) {
INSIST(request->timer == NULL);
req_destroy(request);
*requestp = NULL;
}
/***

View File

@ -1129,6 +1129,7 @@ resquery_destroy(resquery_t **queryp) {
REQUIRE(queryp != NULL);
query = *queryp;
*queryp = NULL;
REQUIRE(!ISC_LINK_LINKED(query, link));
INSIST(query->tcpsocket == NULL);
@ -1144,7 +1145,6 @@ resquery_destroy(resquery_t **queryp) {
query->magic = 0;
isc_mem_put(query->mctx, query, sizeof(*query));
*queryp = NULL;
if (empty)
empty_bucket(res);
@ -10339,12 +10339,11 @@ dns_resolver_detach(dns_resolver_t **resp) {
REQUIRE(resp != NULL);
res = *resp;
*resp = NULL;
REQUIRE(VALID_RESOLVER(res));
RTRACE("detach");
*resp = NULL;
if (isc_refcount_decrement(&res->references) == 1) {
LOCK(&res->lock);
INSIST(atomic_load_acquire(&res->exiting));
@ -10684,6 +10683,7 @@ dns_resolver_destroyfetch(dns_fetch_t **fetchp) {
REQUIRE(fetchp != NULL);
fetch = *fetchp;
*fetchp = NULL;
REQUIRE(DNS_FETCH_VALID(fetch));
fctx = fetch->private;
REQUIRE(VALID_FCTX(fctx));
@ -10712,7 +10712,6 @@ dns_resolver_destroyfetch(dns_fetch_t **fetchp) {
UNLOCK(&res->buckets[bucketnum].lock);
isc_mem_putanddetach(&fetch->mctx, fetch, sizeof(*fetch));
*fetchp = NULL;
if (bucket_empty)
empty_bucket(res);

View File

@ -247,12 +247,11 @@ dns_sdb_unregister(dns_sdbimplementation_t **sdbimp) {
REQUIRE(sdbimp != NULL && *sdbimp != NULL);
imp = *sdbimp;
*sdbimp = NULL;
dns_db_unregister(&imp->dbimp);
isc_mutex_destroy(&imp->driverlock);
isc_mem_putanddetach(&imp->mctx, imp, sizeof(dns_sdbimplementation_t));
*sdbimp = NULL;
}
static inline unsigned int

View File

@ -2068,6 +2068,7 @@ dns_sdlzunregister(dns_sdlzimplementation_t **sdlzimp) {
REQUIRE(sdlzimp != NULL && *sdlzimp != NULL);
imp = *sdlzimp;
*sdlzimp = NULL;
/* Unregister the DLZ driver implementation */
dns_dlzunregister(&imp->dlz_imp);
@ -2080,8 +2081,6 @@ dns_sdlzunregister(dns_sdlzimplementation_t **sdlzimp) {
* remove it from the memory context.
*/
isc_mem_putanddetach(&imp->mctx, imp, sizeof(dns_sdlzimplementation_t));
*sdlzimp = NULL;
}

View File

@ -119,8 +119,8 @@ dns_ssutable_detach(dns_ssutable_t **tablep) {
REQUIRE(tablep != NULL);
table = *tablep;
REQUIRE(VALID_SSUTABLE(table));
*tablep = NULL;
REQUIRE(VALID_SSUTABLE(table));
if (isc_refcount_decrement(&table->references) == 1) {
destroy(table);

View File

@ -131,6 +131,7 @@ dns_tkeyctx_destroy(dns_tkeyctx_t **tctxp) {
REQUIRE(tctxp != NULL && *tctxp != NULL);
tctx = *tctxp;
*tctxp = NULL;
mctx = tctx->mctx;
if (tctx->dhkey != NULL)
@ -146,7 +147,6 @@ dns_tkeyctx_destroy(dns_tkeyctx_t **tctxp) {
if (tctx->gsscred != NULL)
dst_gssapi_releasecred(&tctx->gsscred);
isc_mem_putanddetach(&mctx, tctx, sizeof(dns_tkeyctx_t));
*tctxp = NULL;
}
static isc_result_t

View File

@ -109,6 +109,7 @@ dns_tsec_destroy(dns_tsec_t **tsecp) {
REQUIRE(tsecp != NULL && *tsecp != NULL);
tsec = *tsecp;
*tsecp = NULL;
REQUIRE(DNS_TSEC_VALID(tsec));
switch (tsec->type) {
@ -125,8 +126,6 @@ dns_tsec_destroy(dns_tsec_t **tsecp) {
tsec->magic = 0;
isc_mem_put(tsec->mctx, tsec, sizeof(*tsec));
*tsecp = NULL;
}
dns_tsectype_t

View File

@ -3307,6 +3307,7 @@ dns_validator_destroy(dns_validator_t **validatorp) {
REQUIRE(validatorp != NULL);
val = *validatorp;
*validatorp = NULL;
REQUIRE(VALID_VALIDATOR(val));
LOCK(&val->lock);
@ -3319,8 +3320,6 @@ dns_validator_destroy(dns_validator_t **validatorp) {
if (want_destroy) {
destroy(val);
}
*validatorp = NULL;
}
static void

View File

@ -667,8 +667,8 @@ dns_view_weakdetach(dns_view_t **viewp) {
REQUIRE(viewp != NULL);
view = *viewp;
REQUIRE(DNS_VIEW_VALID(view));
*viewp = NULL;
REQUIRE(DNS_VIEW_VALID(view));
if (isc_refcount_decrement(&view->weakrefs) == 1) {
destroy(view);

View File

@ -701,10 +701,10 @@ dns_xfrin_attach(dns_xfrin_ctx_t *source, dns_xfrin_ctx_t **target) {
void
dns_xfrin_detach(dns_xfrin_ctx_t **xfrp) {
dns_xfrin_ctx_t *xfr = *xfrp;
*xfrp = NULL;
INSIST(xfr->refcount > 0);
xfr->refcount--;
maybe_free(xfr);
*xfrp = NULL;
}
static void

View File

@ -16987,13 +16987,12 @@ dns_zonemgr_detach(dns_zonemgr_t **zmgrp) {
REQUIRE(zmgrp != NULL);
zmgr = *zmgrp;
*zmgrp = NULL;
REQUIRE(DNS_ZONEMGR_VALID(zmgr));
if (isc_refcount_decrement(&zmgr->refs) == 1) {
zonemgr_free(zmgr);
}
*zmgrp = NULL;
}
isc_result_t
@ -17429,9 +17428,8 @@ zonemgr_putio(dns_io_t **iop) {
REQUIRE(iop != NULL);
io = *iop;
REQUIRE(DNS_IO_VALID(io));
*iop = NULL;
REQUIRE(DNS_IO_VALID(io));
INSIST(!ISC_LINK_LINKED(io, link));
INSIST(io->event == NULL);

View File

@ -275,6 +275,7 @@ irs_dnsconf_destroy(irs_dnsconf_t **confp) {
REQUIRE(confp != NULL);
conf = *confp;
*confp = NULL;
REQUIRE(IRS_DNSCONF_VALID(conf));
while ((keyent = ISC_LIST_HEAD(conf->trusted_keylist)) != NULL) {
@ -287,8 +288,6 @@ irs_dnsconf_destroy(irs_dnsconf_t **confp) {
}
isc_mem_put(conf->mctx, conf, sizeof(*conf));
*confp = NULL;
}
irs_dnsconf_dnskeylist_t *

View File

@ -605,6 +605,7 @@ irs_resconf_destroy(irs_resconf_t **confp) {
REQUIRE(confp != NULL);
conf = *confp;
*confp = NULL;
REQUIRE(IRS_RESCONF_VALID(conf));
while ((searchentry = ISC_LIST_HEAD(conf->searchlist)) != NULL) {
@ -626,8 +627,6 @@ irs_resconf_destroy(irs_resconf_t **confp) {
}
isc_mem_put(conf->mctx, conf, sizeof(*conf));
*confp = NULL;
}
isc_sockaddrlist_t *

View File

@ -609,7 +609,7 @@ isc_buffer_free(isc_buffer_t **dynbuffer) {
REQUIRE((*dynbuffer)->mctx != NULL);
dbuf = *dynbuffer;
*dynbuffer = NULL; /* destroy external reference */
*dynbuffer = NULL;/* destroy external reference */
mctx = dbuf->mctx;
dbuf->mctx = NULL;

View File

@ -101,9 +101,8 @@ isc_counter_detach(isc_counter_t **counterp) {
REQUIRE(counterp != NULL && *counterp != NULL);
counter = *counterp;
REQUIRE(VALID_COUNTER(counter));
*counterp = NULL;
REQUIRE(VALID_COUNTER(counter));
if (isc_refcount_decrement(&counter->references) == 1) {
destroy(counter);

View File

@ -84,6 +84,7 @@ isc_event_free(isc_event_t **eventp) {
REQUIRE(eventp != NULL);
event = *eventp;
*eventp = NULL;
REQUIRE(event != NULL);
REQUIRE(!ISC_LINK_LINKED(event, ev_link));
@ -91,6 +92,4 @@ isc_event_free(isc_event_t **eventp) {
if (event->ev_destroy != NULL)
(event->ev_destroy)(event);
*eventp = NULL;
}

View File

@ -112,6 +112,7 @@ isc_heap_destroy(isc_heap_t **heapp) {
REQUIRE(heapp != NULL);
heap = *heapp;
*heapp = NULL;
REQUIRE(VALID_HEAP(heap));
if (heap->array != NULL)
@ -119,8 +120,6 @@ isc_heap_destroy(isc_heap_t **heapp) {
heap->size * sizeof(void *));
heap->magic = 0;
isc_mem_putanddetach(&heap->mctx, heap, sizeof(*heap));
*heapp = NULL;
}
static bool

View File

@ -228,10 +228,9 @@ isc_ht_iter_destroy(isc_ht_iter_t **itp) {
REQUIRE(itp != NULL && *itp != NULL);
it = *itp;
*itp = NULL;
ht = it->ht;
isc_mem_put(ht->mctx, it, sizeof(isc_ht_iter_t));
*itp = NULL;
}
isc_result_t

View File

@ -119,6 +119,7 @@ isc_lex_destroy(isc_lex_t **lexp) {
REQUIRE(lexp != NULL);
lex = *lexp;
*lexp = NULL;
REQUIRE(VALID_LEX(lex));
while (!EMPTY(lex->sources))
@ -127,8 +128,6 @@ isc_lex_destroy(isc_lex_t **lexp) {
isc_mem_put(lex->mctx, lex->data, lex->max_token + 1);
lex->magic = 0;
isc_mem_put(lex->mctx, lex, sizeof(*lex));
*lexp = NULL;
}
unsigned int

View File

@ -431,6 +431,7 @@ isc_log_destroy(isc_log_t **lctxp) {
REQUIRE(lctxp != NULL && VALID_CONTEXT(*lctxp));
lctx = *lctxp;
*lctxp = NULL;
mctx = lctx->mctx;
if (lctx->logconfig != NULL) {
@ -458,8 +459,6 @@ isc_log_destroy(isc_log_t **lctxp) {
lctx->magic = 0;
isc_mem_putanddetach(&mctx, lctx, sizeof(*lctx));
*lctxp = NULL;
}
void
@ -474,6 +473,7 @@ isc_logconfig_destroy(isc_logconfig_t **lcfgp) {
REQUIRE(lcfgp != NULL && VALID_CONFIG(*lcfgp));
lcfg = *lcfgp;
*lcfgp = NULL;
/*
* This function cannot be called with a logconfig that is in
@ -524,8 +524,6 @@ isc_logconfig_destroy(isc_logconfig_t **lcfgp) {
lcfg->magic = 0;
isc_mem_put(mctx, lcfg, sizeof(*lcfg));
*lcfgp = NULL;
}
void

View File

@ -237,6 +237,7 @@ nm_destroy(isc_nm_t **mgr0) {
REQUIRE(!isc__nm_in_netthread());
isc_nm_t *mgr = *mgr0;
*mgr0 = NULL;
isc_refcount_destroy(&mgr->references);
@ -300,7 +301,6 @@ nm_destroy(isc_nm_t **mgr0) {
isc_mem_put(mgr->mctx, mgr->workers,
mgr->nworkers * sizeof(isc__networker_t));
isc_mem_putanddetach(&mgr->mctx, mgr, sizeof(*mgr));
*mgr0 = NULL;
}
void

View File

@ -110,6 +110,7 @@ isc_pool_expand(isc_pool_t **sourcep, unsigned int count,
REQUIRE(targetp != NULL && *targetp == NULL);
pool = *sourcep;
*sourcep = NULL;
if (count > pool->count) {
isc_pool_t *newpool = NULL;
unsigned int i;
@ -143,7 +144,6 @@ isc_pool_expand(isc_pool_t **sourcep, unsigned int count,
pool = newpool;
}
*sourcep = NULL;
*targetp = pool;
return (ISC_R_SUCCESS);
}
@ -152,11 +152,11 @@ void
isc_pool_destroy(isc_pool_t **poolp) {
unsigned int i;
isc_pool_t *pool = *poolp;
*poolp = NULL;
for (i = 0; i < pool->count; i++) {
if (pool->free != NULL && pool->pool[i] != NULL)
pool->free(&pool->pool[i]);
}
isc_mem_put(pool->mctx, pool->pool, pool->count * sizeof(void *));
isc_mem_putanddetach(&pool->mctx, pool, sizeof(*pool));
*poolp = NULL;
}

View File

@ -296,12 +296,11 @@ isc_ratelimiter_detach(isc_ratelimiter_t **rlp) {
REQUIRE(rlp != NULL && *rlp != NULL);
rl = *rlp;
*rlp = NULL;
if (isc_refcount_decrement(&rl->references) == 1) {
ratelimiter_free(rl);
}
*rlp = NULL;
}
isc_result_t

View File

@ -88,6 +88,7 @@ isc_symtab_destroy(isc_symtab_t **symtabp) {
REQUIRE(symtabp != NULL);
symtab = *symtabp;
*symtabp = NULL;
REQUIRE(VALID_SYMTAB(symtab));
for (i = 0; i < symtab->size; i++) {
@ -105,8 +106,6 @@ isc_symtab_destroy(isc_symtab_t **symtabp) {
symtab->size * sizeof(eltlist_t));
symtab->magic = 0;
isc_mem_putanddetach(&symtab->mctx, symtab, sizeof(*symtab));
*symtabp = NULL;
}
static inline unsigned int

View File

@ -492,6 +492,7 @@ task_send(isc__task_t *task, isc_event_t **eventp, int c) {
REQUIRE(eventp != NULL);
event = *eventp;
*eventp = NULL;
REQUIRE(event != NULL);
REQUIRE(event->ev_type > 0);
REQUIRE(task->state != task_state_done);
@ -511,7 +512,6 @@ task_send(isc__task_t *task, isc_event_t **eventp, int c) {
task->state == task_state_pausing);
ENQUEUE(task->events, event, ev_link);
task->nevents++;
*eventp = NULL;
return (was_idle);
}

View File

@ -35,7 +35,7 @@ struct isc_taskpool {
*** Functions.
***/
static isc_result_t
static void
alloc_pool(isc_taskmgr_t *tmgr, isc_mem_t *mctx, unsigned int ntasks,
unsigned int quantum, isc_taskpool_t **poolp)
{
@ -50,11 +50,11 @@ alloc_pool(isc_taskmgr_t *tmgr, isc_mem_t *mctx, unsigned int ntasks,
pool->quantum = quantum;
pool->tmgr = tmgr;
pool->tasks = isc_mem_get(mctx, ntasks * sizeof(isc_task_t *));
for (i = 0; i < ntasks; i++)
for (i = 0; i < ntasks; i++) {
pool->tasks[i] = NULL;
}
*poolp = pool;
return (ISC_R_SUCCESS);
}
isc_result_t
@ -69,9 +69,7 @@ isc_taskpool_create(isc_taskmgr_t *tmgr, isc_mem_t *mctx,
INSIST(ntasks > 0);
/* Allocate the pool structure */
result = alloc_pool(tmgr, mctx, ntasks, quantum, &pool);
if (result != ISC_R_SUCCESS)
return (result);
alloc_pool(tmgr, mctx, ntasks, quantum, &pool);
/* Create the tasks */
for (i = 0; i < ntasks; i++) {
@ -109,15 +107,14 @@ isc_taskpool_expand(isc_taskpool_t **sourcep, unsigned int size,
REQUIRE(targetp != NULL && *targetp == NULL);
pool = *sourcep;
*sourcep = NULL;
if (size > pool->ntasks) {
isc_taskpool_t *newpool = NULL;
unsigned int i;
/* Allocate a new pool structure */
result = alloc_pool(pool->tmgr, pool->mctx, size,
pool->quantum, &newpool);
if (result != ISC_R_SUCCESS)
return (result);
alloc_pool(pool->tmgr, pool->mctx, size,
pool->quantum, &newpool);
/* Copy over the tasks from the old pool */
for (i = 0; i < pool->ntasks; i++) {
@ -130,6 +127,7 @@ isc_taskpool_expand(isc_taskpool_t **sourcep, unsigned int size,
result = isc_task_create(pool->tmgr, pool->quantum,
&newpool->tasks[i]);
if (result != ISC_R_SUCCESS) {
*sourcep = pool;
isc_taskpool_destroy(&newpool);
return (result);
}
@ -140,7 +138,6 @@ isc_taskpool_expand(isc_taskpool_t **sourcep, unsigned int size,
pool = newpool;
}
*sourcep = NULL;
*targetp = pool;
return (ISC_R_SUCCESS);
}
@ -149,6 +146,7 @@ void
isc_taskpool_destroy(isc_taskpool_t **poolp) {
unsigned int i;
isc_taskpool_t *pool = *poolp;
*poolp = NULL;
for (i = 0; i < pool->ntasks; i++) {
if (pool->tasks[i] != NULL)
isc_task_detach(&pool->tasks[i]);
@ -156,7 +154,6 @@ isc_taskpool_destroy(isc_taskpool_t **poolp) {
isc_mem_put(pool->mctx, pool->tasks,
pool->ntasks * sizeof(isc_task_t *));
isc_mem_putanddetach(&pool->mctx, pool, sizeof(*pool));
*poolp = NULL;
}
void

View File

@ -282,6 +282,7 @@ isc_interfaceiter_destroy(isc_interfaceiter_t **iterp)
isc_interfaceiter_t *iter;
REQUIRE(iterp != NULL);
iter = *iterp;
*iterp = NULL;
REQUIRE(VALID_IFITER(iter));
internal_destroy(iter);
@ -290,5 +291,4 @@ isc_interfaceiter_destroy(isc_interfaceiter_t **iterp)
iter->magic = 0;
isc_mem_put(iter->mctx, iter, sizeof(*iter));
*iterp = NULL;
}

View File

@ -1931,6 +1931,7 @@ allocate_socket(isc__socketmgr_t *manager, isc_sockettype_t type,
static void
free_socket(isc__socket_t **socketp) {
isc__socket_t *sock = *socketp;
*socketp = NULL;
INSIST(VALID_SOCKET(sock));
isc_refcount_destroy(&sock->references);
@ -1949,8 +1950,6 @@ free_socket(isc__socket_t **socketp) {
isc_mutex_destroy(&sock->lock);
isc_mem_put(sock->manager->mctx, sock, sizeof(*sock));
*socketp = NULL;
}
#ifdef SO_RCVBUF

View File

@ -516,6 +516,7 @@ isc_interfaceiter_destroy(isc_interfaceiter_t **iterp) {
isc_interfaceiter_t *iter;
REQUIRE(iterp != NULL);
iter = *iterp;
*iterp = NULL;
REQUIRE(VALID_IFITER(iter));
if (iter->buf4 != NULL)
@ -525,5 +526,4 @@ isc_interfaceiter_destroy(isc_interfaceiter_t **iterp) {
iter->magic = 0;
isc_mem_put(iter->mctx, iter, sizeof(*iter));
*iterp = NULL;
}

View File

@ -1752,6 +1752,7 @@ isc_socket_detach(isc_socket_t **socketp) {
REQUIRE(socketp != NULL);
sock = *socketp;
*socketp = NULL;
REQUIRE(VALID_SOCKET(sock));
LOCK(&sock->lock);
@ -1771,8 +1772,6 @@ isc_socket_detach(isc_socket_t **socketp) {
}
maybe_free_socket(&sock, __LINE__); /* Also unlocks the socket lock */
*socketp = NULL;
}
isc_result_t
@ -2565,6 +2564,7 @@ isc_socketmgr_destroy(isc_socketmgr_t **managerp) {
REQUIRE(managerp != NULL);
manager = *managerp;
*managerp = NULL;
REQUIRE(VALID_MANAGER(manager));
LOCK(&manager->lock);
@ -2606,8 +2606,6 @@ isc_socketmgr_destroy(isc_socketmgr_t **managerp) {
}
manager->magic = 0;
isc_mem_putanddetach(&manager->mctx, manager, sizeof(*manager));
*managerp = NULL;
}
static void

View File

@ -115,6 +115,7 @@ isccc_sexpr_free(isccc_sexpr_t **sexprp) {
isccc_sexpr_t *item;
sexpr = *sexprp;
*sexprp = NULL;
if (sexpr == NULL)
return;
switch (sexpr->type) {
@ -134,8 +135,6 @@ isccc_sexpr_free(isccc_sexpr_t **sexprp) {
break;
}
free(sexpr);
*sexprp = NULL;
}
static bool

View File

@ -110,6 +110,7 @@ isccc_symtab_destroy(isccc_symtab_t **symtabp) {
REQUIRE(symtabp != NULL);
symtab = *symtabp;
*symtabp = NULL;
REQUIRE(VALID_SYMTAB(symtab));
for (i = 0; i < symtab->size; i++) {
@ -123,8 +124,6 @@ isccc_symtab_destroy(isccc_symtab_t **symtabp) {
free(symtab->table);
symtab->magic = 0;
free(symtab);
*symtabp = NULL;
}
static inline unsigned int

View File

@ -2382,17 +2382,17 @@ clientmgr_attach(ns_clientmgr_t *source, ns_clientmgr_t **targetp) {
static void
clientmgr_detach(ns_clientmgr_t **mp) {
int32_t oldrefs;
ns_clientmgr_t *mgr = *mp;
int32_t oldrefs = isc_refcount_decrement(&mgr->references);
*mp = NULL;
oldrefs = isc_refcount_decrement(&mgr->references);
isc_log_write(ns_lctx, NS_LOGCATEGORY_CLIENT,
NS_LOGMODULE_CLIENT, ISC_LOG_DEBUG(3),
"clientmgr @%p detach: %d", mgr, oldrefs - 1);
if (oldrefs == 1) {
clientmgr_destroy(mgr);
}
*mp = NULL;
}
static void
@ -2506,6 +2506,7 @@ ns_clientmgr_destroy(ns_clientmgr_t **managerp) {
REQUIRE(managerp != NULL);
manager = *managerp;
*managerp = NULL;
REQUIRE(VALID_MANAGER(manager));
MTRACE("destroy");
@ -2529,8 +2530,6 @@ ns_clientmgr_destroy(ns_clientmgr_t **managerp) {
if (isc_refcount_decrement(&manager->references) == 1) {
clientmgr_destroy(manager);
}
*managerp = NULL;
}
isc_sockaddr_t *

View File

@ -347,12 +347,12 @@ ns_interfacemgr_attach(ns_interfacemgr_t *source, ns_interfacemgr_t **target) {
void
ns_interfacemgr_detach(ns_interfacemgr_t **targetp) {
ns_interfacemgr_t *target = *targetp;
*targetp = NULL;
REQUIRE(target != NULL);
REQUIRE(NS_INTERFACEMGR_VALID(target));
if (isc_refcount_decrement(&target->references) == 1) {
ns_interfacemgr_destroy(target);
}
*targetp = NULL;
}
void
@ -607,12 +607,12 @@ ns_interface_attach(ns_interface_t *source, ns_interface_t **target) {
void
ns_interface_detach(ns_interface_t **targetp) {
ns_interface_t *target = *targetp;
*targetp = NULL;
REQUIRE(target != NULL);
REQUIRE(NS_INTERFACE_VALID(target));
if (isc_refcount_decrement(&target->references) == 1) {
ns_interface_destroy(target);
}
*targetp = NULL;
}
/*%

View File

@ -81,11 +81,11 @@ ns_listenlist_attach(ns_listenlist_t *source, ns_listenlist_t **target) {
void
ns_listenlist_detach(ns_listenlist_t **listp) {
ns_listenlist_t *list = *listp;
*listp = NULL;
INSIST(list->refcount > 0);
list->refcount--;
if (list->refcount == 0)
destroy(list);
*listp = NULL;
}
isc_result_t

View File

@ -841,6 +841,7 @@ ns_test_qctx_destroy(query_ctx_t **qctxp) {
REQUIRE(*qctxp != NULL);
qctx = *qctxp;
*qctxp = NULL;
if (qctx->zone != NULL) {
dns_zone_detach(&qctx->zone);
@ -853,7 +854,6 @@ ns_test_qctx_destroy(query_ctx_t **qctxp) {
}
isc_mem_put(mctx, qctx, sizeof(*qctx));
*qctxp = NULL;
}
ns_hookresult_t

View File

@ -558,8 +558,8 @@ compound_rrstream_create(isc_mem_t *mctx, rrstream_t **soa_stream,
s->state = -1;
s->result = ISC_R_FAILURE;
*soa_stream = NULL;
*data_stream = NULL;
*soa_stream = NULL;
*sp = (rrstream_t *) s;
return (ISC_R_SUCCESS);
}
@ -1605,6 +1605,7 @@ sendstream(xfrout_ctx_t *xfr) {
static void
xfrout_ctx_destroy(xfrout_ctx_t **xfrp) {
xfrout_ctx_t *xfr = *xfrp;
*xfrp = NULL;
INSIST(xfr->sends == 0);
@ -1629,8 +1630,6 @@ xfrout_ctx_destroy(xfrout_ctx_t **xfrp) {
dns_db_detach(&xfr->db);
isc_mem_putanddetach(&xfr->mctx, xfr, sizeof(*xfr));
*xfrp = NULL;
}
static void