From bc1d4c9cb44432e24d2db5c762eda64ae9b9a93e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Sat, 8 Feb 2020 04:37:54 -0800 Subject: [PATCH] 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. --- bin/dnssec/dnssec-cds.c | 2 +- bin/named/controlconf.c | 2 +- bin/nsupdate/nsupdate.c | 2 +- bin/tests/system/dyndb/driver/instance.c | 3 +-- ...spatch => null-the-pointer-early.disabled} | 0 lib/dns/adb.c | 6 +++--- lib/dns/badcache.c | 2 +- lib/dns/byaddr.c | 3 +-- lib/dns/cache.c | 2 +- lib/dns/catz.c | 3 +-- lib/dns/client.c | 3 +-- lib/dns/dbtable.c | 2 +- lib/dns/diff.c | 2 +- lib/dns/dispatch.c | 18 +++++----------- lib/dns/dnsrps.c | 2 +- lib/dns/dnssec.c | 2 +- lib/dns/dnstap.c | 3 +-- lib/dns/dst_api.c | 2 +- lib/dns/dyndb.c | 6 ++---- lib/dns/forward.c | 3 +-- lib/dns/journal.c | 2 +- lib/dns/lookup.c | 3 +-- lib/dns/master.c | 3 +-- lib/dns/masterdump.c | 3 +-- lib/dns/message.c | 2 +- lib/dns/peer.c | 6 ++---- lib/dns/rbt.c | 5 +++-- lib/dns/request.c | 8 +++---- lib/dns/resolver.c | 7 +++---- lib/dns/sdb.c | 3 +-- lib/dns/sdlz.c | 3 +-- lib/dns/ssu.c | 2 +- lib/dns/tkey.c | 2 +- lib/dns/tsec.c | 3 +-- lib/dns/validator.c | 3 +-- lib/dns/view.c | 2 +- lib/dns/xfrin.c | 2 +- lib/dns/zone.c | 6 ++---- lib/irs/dnsconf.c | 3 +-- lib/irs/resconf.c | 3 +-- lib/isc/buffer.c | 2 +- lib/isc/counter.c | 3 +-- lib/isc/event.c | 3 +-- lib/isc/heap.c | 3 +-- lib/isc/ht.c | 3 +-- lib/isc/lex.c | 3 +-- lib/isc/log.c | 6 ++---- lib/isc/netmgr/netmgr.c | 2 +- lib/isc/pool.c | 4 ++-- lib/isc/ratelimiter.c | 3 +-- lib/isc/symtab.c | 3 +-- lib/isc/task.c | 2 +- lib/isc/taskpool.c | 21 ++++++++----------- lib/isc/unix/interfaceiter.c | 2 +- lib/isc/unix/socket.c | 3 +-- lib/isc/win32/interfaceiter.c | 2 +- lib/isc/win32/socket.c | 6 ++---- lib/isccc/sexpr.c | 3 +-- lib/isccc/symtab.c | 3 +-- lib/ns/client.c | 9 ++++---- lib/ns/interfacemgr.c | 4 ++-- lib/ns/listenlist.c | 2 +- lib/ns/tests/nstest.c | 2 +- lib/ns/xfrout.c | 5 ++--- 64 files changed, 94 insertions(+), 144 deletions(-) rename cocci/{null-the-pointer-early.spatch => null-the-pointer-early.disabled} (100%) diff --git a/bin/dnssec/dnssec-cds.c b/bin/dnssec/dnssec-cds.c index 283e754cdc..57c34d9e63 100644 --- a/bin/dnssec/dnssec-cds.c +++ b/bin/dnssec/dnssec-cds.c @@ -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; } /* diff --git a/bin/named/controlconf.c b/bin/named/controlconf.c index f07590652a..41fd61a4ee 100644 --- a/bin/named/controlconf.c +++ b/bin/named/controlconf.c @@ -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; } diff --git a/bin/nsupdate/nsupdate.c b/bin/nsupdate/nsupdate.c index c431ebe39f..687fc3b0f0 100644 --- a/bin/nsupdate/nsupdate.c +++ b/bin/nsupdate/nsupdate.c @@ -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); } diff --git a/bin/tests/system/dyndb/driver/instance.c b/bin/tests/system/dyndb/driver/instance.c index 5650f3ba2e..962df342e2 100644 --- a/bin/tests/system/dyndb/driver/instance.c +++ b/bin/tests/system/dyndb/driver/instance.c @@ -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; } diff --git a/cocci/null-the-pointer-early.spatch b/cocci/null-the-pointer-early.disabled similarity index 100% rename from cocci/null-the-pointer-early.spatch rename to cocci/null-the-pointer-early.disabled diff --git a/lib/dns/adb.c b/lib/dns/adb.c index d7f25494db..d6b7658db3 100644 --- a/lib/dns/adb.c +++ b/lib/dns/adb.c @@ -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; diff --git a/lib/dns/badcache.c b/lib/dns/badcache.c index 389981f849..a2e76f2186 100644 --- a/lib/dns/badcache.c +++ b/lib/dns/badcache.c @@ -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 diff --git a/lib/dns/byaddr.c b/lib/dns/byaddr.c index 5d8dfbf7b8..a1e83bda4d 100644 --- a/lib/dns/byaddr.c +++ b/lib/dns/byaddr.c @@ -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; } diff --git a/lib/dns/cache.c b/lib/dns/cache.c index f20c1de8a6..75ac923f7c 100644 --- a/lib/dns/cache.c +++ b/lib/dns/cache.c @@ -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; diff --git a/lib/dns/catz.c b/lib/dns/catz.c index e175badff2..1c63cac051 100644 --- a/lib/dns/catz.c +++ b/lib/dns/catz.c @@ -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; diff --git a/lib/dns/client.c b/lib/dns/client.c index ad4342be6a..03c2680bcd 100644 --- a/lib/dns/client.c +++ b/lib/dns/client.c @@ -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 diff --git a/lib/dns/dbtable.c b/lib/dns/dbtable.c index db134e44e8..e018fa7e52 100644 --- a/lib/dns/dbtable.c +++ b/lib/dns/dbtable.c @@ -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); diff --git a/lib/dns/diff.c b/lib/dns/diff.c index 3f5d8d2ef6..7789331f90 100644 --- a/lib/dns/diff.c +++ b/lib/dns/diff.c @@ -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 diff --git a/lib/dns/dispatch.c b/lib/dns/dispatch.c index d1b3189138..2c943eeac4 100644 --- a/lib/dns/dispatch.c +++ b/lib/dns/dispatch.c @@ -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 diff --git a/lib/dns/dnsrps.c b/lib/dns/dnsrps.c index c4f68e15b3..8fd9677e22 100644 --- a/lib/dns/dnsrps.c +++ b/lib/dns/dnsrps.c @@ -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 diff --git a/lib/dns/dnssec.c b/lib/dns/dnssec.c index 8f6e04af86..368137ab2f 100644 --- a/lib/dns/dnssec.c +++ b/lib/dns/dnssec.c @@ -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 diff --git a/lib/dns/dnstap.c b/lib/dns/dnstap.c index 1f66035ce6..45ac5a541f 100644 --- a/lib/dns/dnstap.c +++ b/lib/dns/dnstap.c @@ -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; } diff --git a/lib/dns/dst_api.c b/lib/dns/dst_api.c index c778d59f27..964d6df3f8 100644 --- a/lib/dns/dst_api.c +++ b/lib/dns/dst_api.c @@ -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 diff --git a/lib/dns/dyndb.c b/lib/dns/dyndb.c index 5b3c964b81..f00fba1ac0 100644 --- a/lib/dns/dyndb.c +++ b/lib/dns/dyndb.c @@ -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 diff --git a/lib/dns/forward.c b/lib/dns/forward.c index 2ac0b31b95..c42cf73c38 100644 --- a/lib/dns/forward.c +++ b/lib/dns/forward.c @@ -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; } /*** diff --git a/lib/dns/journal.c b/lib/dns/journal.c index f64bc66eed..ce2b28d78e 100644 --- a/lib/dns/journal.c +++ b/lib/dns/journal.c @@ -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; } /* diff --git a/lib/dns/lookup.c b/lib/dns/lookup.c index ad5d77c4d3..d63169d775 100644 --- a/lib/dns/lookup.c +++ b/lib/dns/lookup.c @@ -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; } diff --git a/lib/dns/master.c b/lib/dns/master.c index e7ccc0e04b..a4dd901d8d 100644 --- a/lib/dns/master.c +++ b/lib/dns/master.c @@ -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); diff --git a/lib/dns/masterdump.c b/lib/dns/masterdump.c index b5adeb532e..595000d581 100644 --- a/lib/dns/masterdump.c +++ b/lib/dns/masterdump.c @@ -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); diff --git a/lib/dns/message.c b/lib/dns/message.c index 767db4ce8a..41b9251037 100644 --- a/lib/dns/message.c +++ b/lib/dns/message.c @@ -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); diff --git a/lib/dns/peer.c b/lib/dns/peer.c index bf1ef07d99..8b1fefe045 100644 --- a/lib/dns/peer.c +++ b/lib/dns/peer.c @@ -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 diff --git a/lib/dns/rbt.c b/lib/dns/rbt.c index 34170ce9ab..e968048dfe 100644 --- a/lib/dns/rbt.c +++ b/lib/dns/rbt.c @@ -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--; } diff --git a/lib/dns/request.c b/lib/dns/request.c index ab1d553edd..782075fcf9 100644 --- a/lib/dns/request.c +++ b/lib/dns/request.c @@ -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; } /*** diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c index 55273d8e17..87e8792802 100644 --- a/lib/dns/resolver.c +++ b/lib/dns/resolver.c @@ -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); diff --git a/lib/dns/sdb.c b/lib/dns/sdb.c index 031928322f..3da02d5c29 100644 --- a/lib/dns/sdb.c +++ b/lib/dns/sdb.c @@ -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 diff --git a/lib/dns/sdlz.c b/lib/dns/sdlz.c index f163a9b637..480f9200d4 100644 --- a/lib/dns/sdlz.c +++ b/lib/dns/sdlz.c @@ -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; } diff --git a/lib/dns/ssu.c b/lib/dns/ssu.c index 2b17c8362c..b817722069 100644 --- a/lib/dns/ssu.c +++ b/lib/dns/ssu.c @@ -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); diff --git a/lib/dns/tkey.c b/lib/dns/tkey.c index 258bce17da..f28326e356 100644 --- a/lib/dns/tkey.c +++ b/lib/dns/tkey.c @@ -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 diff --git a/lib/dns/tsec.c b/lib/dns/tsec.c index 2b59ac33e7..cf0055e669 100644 --- a/lib/dns/tsec.c +++ b/lib/dns/tsec.c @@ -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 diff --git a/lib/dns/validator.c b/lib/dns/validator.c index 8fe3aa46f1..4f87c5bc3b 100644 --- a/lib/dns/validator.c +++ b/lib/dns/validator.c @@ -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 diff --git a/lib/dns/view.c b/lib/dns/view.c index 38c6634a36..9396763164 100644 --- a/lib/dns/view.c +++ b/lib/dns/view.c @@ -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); diff --git a/lib/dns/xfrin.c b/lib/dns/xfrin.c index 3b372570b9..66a231b744 100644 --- a/lib/dns/xfrin.c +++ b/lib/dns/xfrin.c @@ -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 diff --git a/lib/dns/zone.c b/lib/dns/zone.c index 8604b5f3dc..d06e3c19d4 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -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); diff --git a/lib/irs/dnsconf.c b/lib/irs/dnsconf.c index d98c220b26..b56190ab6e 100644 --- a/lib/irs/dnsconf.c +++ b/lib/irs/dnsconf.c @@ -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 * diff --git a/lib/irs/resconf.c b/lib/irs/resconf.c index 44f340e399..ff2db506de 100644 --- a/lib/irs/resconf.c +++ b/lib/irs/resconf.c @@ -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 * diff --git a/lib/isc/buffer.c b/lib/isc/buffer.c index 04b081b025..2333c7ec3c 100644 --- a/lib/isc/buffer.c +++ b/lib/isc/buffer.c @@ -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; diff --git a/lib/isc/counter.c b/lib/isc/counter.c index 3270e3370a..9683665920 100644 --- a/lib/isc/counter.c +++ b/lib/isc/counter.c @@ -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); diff --git a/lib/isc/event.c b/lib/isc/event.c index 3df4283c88..938ec9c19a 100644 --- a/lib/isc/event.c +++ b/lib/isc/event.c @@ -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; } diff --git a/lib/isc/heap.c b/lib/isc/heap.c index 52c08f7cf9..006d087bac 100644 --- a/lib/isc/heap.c +++ b/lib/isc/heap.c @@ -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 diff --git a/lib/isc/ht.c b/lib/isc/ht.c index bad7e60fb5..5468eba59f 100644 --- a/lib/isc/ht.c +++ b/lib/isc/ht.c @@ -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 diff --git a/lib/isc/lex.c b/lib/isc/lex.c index f8ed95e14f..e6128c8b58 100644 --- a/lib/isc/lex.c +++ b/lib/isc/lex.c @@ -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 diff --git a/lib/isc/log.c b/lib/isc/log.c index 1b19605226..c3cdc6abd9 100644 --- a/lib/isc/log.c +++ b/lib/isc/log.c @@ -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 diff --git a/lib/isc/netmgr/netmgr.c b/lib/isc/netmgr/netmgr.c index e900d09825..6f929c6d2c 100644 --- a/lib/isc/netmgr/netmgr.c +++ b/lib/isc/netmgr/netmgr.c @@ -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 diff --git a/lib/isc/pool.c b/lib/isc/pool.c index 88b27643c4..fd3af14576 100644 --- a/lib/isc/pool.c +++ b/lib/isc/pool.c @@ -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; } diff --git a/lib/isc/ratelimiter.c b/lib/isc/ratelimiter.c index 8bee4e7e0f..e4f8a0cfc2 100644 --- a/lib/isc/ratelimiter.c +++ b/lib/isc/ratelimiter.c @@ -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 diff --git a/lib/isc/symtab.c b/lib/isc/symtab.c index 021d94c18c..86fcc60dd4 100644 --- a/lib/isc/symtab.c +++ b/lib/isc/symtab.c @@ -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 diff --git a/lib/isc/task.c b/lib/isc/task.c index f859849935..f4dfeaec66 100644 --- a/lib/isc/task.c +++ b/lib/isc/task.c @@ -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); } diff --git a/lib/isc/taskpool.c b/lib/isc/taskpool.c index e5c09dea4a..95a4958e21 100644 --- a/lib/isc/taskpool.c +++ b/lib/isc/taskpool.c @@ -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 diff --git a/lib/isc/unix/interfaceiter.c b/lib/isc/unix/interfaceiter.c index c3da74a98f..5797a848d0 100644 --- a/lib/isc/unix/interfaceiter.c +++ b/lib/isc/unix/interfaceiter.c @@ -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; } diff --git a/lib/isc/unix/socket.c b/lib/isc/unix/socket.c index eebce42f89..d6c39502ce 100644 --- a/lib/isc/unix/socket.c +++ b/lib/isc/unix/socket.c @@ -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 diff --git a/lib/isc/win32/interfaceiter.c b/lib/isc/win32/interfaceiter.c index d8cbaa396e..a135d3b017 100644 --- a/lib/isc/win32/interfaceiter.c +++ b/lib/isc/win32/interfaceiter.c @@ -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; } diff --git a/lib/isc/win32/socket.c b/lib/isc/win32/socket.c index 2d2c67a6bb..95ee49d845 100644 --- a/lib/isc/win32/socket.c +++ b/lib/isc/win32/socket.c @@ -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 diff --git a/lib/isccc/sexpr.c b/lib/isccc/sexpr.c index eae82aa5e1..1e318329b0 100644 --- a/lib/isccc/sexpr.c +++ b/lib/isccc/sexpr.c @@ -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 diff --git a/lib/isccc/symtab.c b/lib/isccc/symtab.c index 18bf32bdbc..ffb2e8a52e 100644 --- a/lib/isccc/symtab.c +++ b/lib/isccc/symtab.c @@ -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 diff --git a/lib/ns/client.c b/lib/ns/client.c index a5867d09b1..8762079524 100644 --- a/lib/ns/client.c +++ b/lib/ns/client.c @@ -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 * diff --git a/lib/ns/interfacemgr.c b/lib/ns/interfacemgr.c index df1fe63aab..f9da16483b 100644 --- a/lib/ns/interfacemgr.c +++ b/lib/ns/interfacemgr.c @@ -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; } /*% diff --git a/lib/ns/listenlist.c b/lib/ns/listenlist.c index f198b5c847..ee08c0cdf3 100644 --- a/lib/ns/listenlist.c +++ b/lib/ns/listenlist.c @@ -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 diff --git a/lib/ns/tests/nstest.c b/lib/ns/tests/nstest.c index d4314693d2..e05f8d8f55 100644 --- a/lib/ns/tests/nstest.c +++ b/lib/ns/tests/nstest.c @@ -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 diff --git a/lib/ns/xfrout.c b/lib/ns/xfrout.c index 7ad4ef96ea..391d4c1238 100644 --- a/lib/ns/xfrout.c +++ b/lib/ns/xfrout.c @@ -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