mirror of
https://github.com/isc-projects/bind9.git
synced 2026-05-28 04:34:54 -04:00
Always check the return from isc_refcount_decrement.
Created isc_refcount_decrement_expect macro to test conditionally the return value to ensure it is in expected range. Converted unchecked isc_refcount_decrement to use isc_refcount_decrement_expect. Converted INSIST(isc_refcount_decrement()...) to isc_refcount_decrement_expect.
This commit is contained in:
parent
92059fc7db
commit
bde5c7632a
16 changed files with 47 additions and 31 deletions
|
|
@ -9664,7 +9664,7 @@ load_zones(named_server_t *server, bool init, bool reconfig) {
|
|||
isc_refcount_increment(&zl->refs);
|
||||
result = dns_view_asyncload(view, reconfig, view_loaded, zl);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
(void)isc_refcount_decrement(&zl->refs);
|
||||
isc_refcount_decrement1(&zl->refs);
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -555,7 +555,7 @@ cache_cleaner_init(dns_cache_t *cache, isc_taskmgr_t *taskmgr,
|
|||
result = isc_task_onshutdown(cleaner->task,
|
||||
cleaner_shutdown_action, cache);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
isc_refcount_decrement(&cleaner->cache->live_tasks);
|
||||
isc_refcount_decrement0(&cleaner->cache->live_tasks);
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||
"cache cleaner: "
|
||||
"isc_task_onshutdown() failed: %s",
|
||||
|
|
@ -1020,7 +1020,7 @@ cleaner_shutdown_action(isc_task_t *task, isc_event_t *event) {
|
|||
/* Make sure we don't reschedule anymore. */
|
||||
(void)isc_task_purge(task, NULL, DNS_EVENT_CACHECLEAN, NULL);
|
||||
|
||||
INSIST(isc_refcount_decrement(&cache->live_tasks) == 1);
|
||||
isc_refcount_decrementz(&cache->live_tasks);
|
||||
|
||||
cache_free(cache);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -582,7 +582,7 @@ dns_client_createx(isc_mem_t *mctx, isc_appctx_t *actx, isc_taskmgr_t *taskmgr,
|
|||
return (ISC_R_SUCCESS);
|
||||
|
||||
cleanup_references:
|
||||
isc_refcount_decrement(&client->references);
|
||||
isc_refcount_decrementz(&client->references);
|
||||
isc_refcount_destroy(&client->references);
|
||||
cleanup_dispatchmgr:
|
||||
if (dispatchv4 != NULL) {
|
||||
|
|
@ -1787,7 +1787,7 @@ dns_client_startrequest(dns_client_t *client, dns_message_t *qmessage,
|
|||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
isc_refcount_decrement(&client->references);
|
||||
isc_refcount_decrement1(&client->references);
|
||||
|
||||
LOCK(&client->lock);
|
||||
ISC_LIST_UNLINK(client->reqctxs, ctx, link);
|
||||
|
|
@ -2946,7 +2946,7 @@ dns_client_startupdate(dns_client_t *client, dns_rdataclass_t rdclass,
|
|||
return (result);
|
||||
}
|
||||
|
||||
isc_refcount_decrement(&client->references);
|
||||
isc_refcount_decrement1(&client->references);
|
||||
*transp = NULL;
|
||||
|
||||
fail:
|
||||
|
|
|
|||
|
|
@ -1046,9 +1046,7 @@ free_rbtdb(dns_rbtdb_t *rbtdb, bool log, isc_event_t *event) {
|
|||
REQUIRE(rbtdb->future_version == NULL);
|
||||
|
||||
if (rbtdb->current_version != NULL) {
|
||||
INSIST(isc_refcount_decrement(
|
||||
&rbtdb->current_version->references) == 1);
|
||||
|
||||
isc_refcount_decrementz(&rbtdb->current_version->references);
|
||||
UNLINK(rbtdb->open_versions, rbtdb->current_version, link);
|
||||
isc_rwlock_destroy(&rbtdb->current_version->glue_rwlock);
|
||||
isc_refcount_destroy(&rbtdb->current_version->references);
|
||||
|
|
@ -8703,7 +8701,7 @@ dns_rbtdb_create(isc_mem_t *mctx, const dns_name_t *origin, dns_dbtype_t type,
|
|||
rbtdb->next_serial = 2;
|
||||
rbtdb->current_version = allocate_version(mctx, 1, 1, false);
|
||||
if (rbtdb->current_version == NULL) {
|
||||
isc_refcount_decrement(&rbtdb->references);
|
||||
isc_refcount_decrementz(&rbtdb->references);
|
||||
free_rbtdb(rbtdb, false, NULL);
|
||||
return (ISC_R_NOMEMORY);
|
||||
}
|
||||
|
|
@ -8724,7 +8722,7 @@ dns_rbtdb_create(isc_mem_t *mctx, const dns_name_t *origin, dns_dbtype_t type,
|
|||
isc_mem_put(mctx, rbtdb->current_version,
|
||||
sizeof(*rbtdb->current_version));
|
||||
rbtdb->current_version = NULL;
|
||||
isc_refcount_decrement(&rbtdb->references);
|
||||
isc_refcount_decrementz(&rbtdb->references);
|
||||
free_rbtdb(rbtdb, false, NULL);
|
||||
return (result);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4487,7 +4487,7 @@ fctx_unlink(fetchctx_t *fctx) {
|
|||
|
||||
ISC_LIST_UNLINK(res->buckets[bucketnum].fctxs, fctx, link);
|
||||
|
||||
REQUIRE(atomic_fetch_sub_release(&res->nfctx, 1) > 0);
|
||||
INSIST(atomic_fetch_sub_release(&res->nfctx, 1) > 0);
|
||||
|
||||
dec_stats(res, dns_resstatscounter_nfetch);
|
||||
|
||||
|
|
@ -5185,7 +5185,7 @@ fctx_create(dns_resolver_t *res, const dns_name_t *name, dns_rdatatype_t type,
|
|||
|
||||
ISC_LIST_APPEND(res->buckets[bucketnum].fctxs, fctx, link);
|
||||
|
||||
REQUIRE(atomic_fetch_add_relaxed(&res->nfctx, 1) < UINT32_MAX);
|
||||
INSIST(atomic_fetch_add_relaxed(&res->nfctx, 1) < UINT32_MAX);
|
||||
|
||||
inc_stats(res, dns_resstatscounter_nfetch);
|
||||
|
||||
|
|
|
|||
|
|
@ -1502,9 +1502,9 @@ cleanup_task:
|
|||
dns_rbt_destroy(&zones->rbt);
|
||||
|
||||
cleanup_rbt:
|
||||
isc_refcount_decrement(&zones->irefs);
|
||||
isc_refcount_decrementz(&zones->irefs);
|
||||
isc_refcount_destroy(&zones->irefs);
|
||||
isc_refcount_decrement(&zones->refs);
|
||||
isc_refcount_decrementz(&zones->refs);
|
||||
isc_refcount_destroy(&zones->refs);
|
||||
|
||||
isc_mutex_destroy(&zones->maint_lock);
|
||||
|
|
@ -1587,7 +1587,7 @@ cleanup_ht:
|
|||
isc_timer_detach(&zone->updatetimer);
|
||||
|
||||
cleanup_timer:
|
||||
isc_refcount_decrement(&zone->refs);
|
||||
isc_refcount_decrementz(&zone->refs);
|
||||
isc_refcount_destroy(&zone->refs);
|
||||
|
||||
isc_mem_put(rpzs->mctx, zone, sizeof(*zone));
|
||||
|
|
|
|||
|
|
@ -638,7 +638,7 @@ getnodedata(dns_db_t *db, const dns_name_t *name, bool create,
|
|||
}
|
||||
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
isc_refcount_decrement(&node->references);
|
||||
isc_refcount_decrementz(&node->references);
|
||||
destroynode(node);
|
||||
return (result);
|
||||
}
|
||||
|
|
@ -650,7 +650,7 @@ getnodedata(dns_db_t *db, const dns_name_t *name, bool create,
|
|||
sdlz->dbdata, node);
|
||||
MAYBE_UNLOCK(sdlz->dlzimp);
|
||||
if (result != ISC_R_SUCCESS && result != ISC_R_NOTIMPLEMENTED) {
|
||||
isc_refcount_decrement(&node->references);
|
||||
isc_refcount_decrementz(&node->references);
|
||||
destroynode(node);
|
||||
return (result);
|
||||
}
|
||||
|
|
@ -1299,7 +1299,7 @@ dbiterator_destroy(dns_dbiterator_t **iteratorp) {
|
|||
dns_sdlznode_t *node;
|
||||
node = ISC_LIST_HEAD(sdlziter->nodelist);
|
||||
ISC_LIST_UNLINK(sdlziter->nodelist, node, link);
|
||||
isc_refcount_decrement(&node->references);
|
||||
isc_refcount_decrementz(&node->references);
|
||||
destroynode(node);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -349,7 +349,7 @@ dns_tsigkey_createfromkey(const dns_name_t *name, const dns_name_t *algorithm,
|
|||
cleanup_refs:
|
||||
tkey->magic = 0;
|
||||
while (refs-- > 0) {
|
||||
isc_refcount_decrement(&tkey->refs);
|
||||
isc_refcount_decrement0(&tkey->refs);
|
||||
}
|
||||
isc_refcount_destroy(&tkey->refs);
|
||||
|
||||
|
|
|
|||
|
|
@ -314,10 +314,10 @@ cleanup_dynkeys:
|
|||
}
|
||||
|
||||
cleanup_weakrefs:
|
||||
isc_refcount_decrement(&view->weakrefs);
|
||||
isc_refcount_decrementz(&view->weakrefs);
|
||||
isc_refcount_destroy(&view->weakrefs);
|
||||
|
||||
isc_refcount_decrement(&view->references);
|
||||
isc_refcount_decrementz(&view->references);
|
||||
isc_refcount_destroy(&view->references);
|
||||
|
||||
if (view->fwdtable != NULL) {
|
||||
|
|
|
|||
|
|
@ -1146,7 +1146,7 @@ dns_zone_create(dns_zone_t **zonep, isc_mem_t *mctx) {
|
|||
return (ISC_R_SUCCESS);
|
||||
|
||||
free_refs:
|
||||
isc_refcount_decrement(&zone->erefs);
|
||||
isc_refcount_decrement0(&zone->erefs);
|
||||
isc_refcount_destroy(&zone->erefs);
|
||||
isc_refcount_destroy(&zone->irefs);
|
||||
|
||||
|
|
|
|||
|
|
@ -375,8 +375,8 @@ asyncload(dns_zone_t *zone, void *zt_) {
|
|||
* Caller is holding a reference to zt->loads_pending
|
||||
* and zt->references so these can't decrement to zero.
|
||||
*/
|
||||
INSIST(isc_refcount_decrement(&zt->loads_pending) > 1);
|
||||
INSIST(isc_refcount_decrement(&zt->references) > 1);
|
||||
isc_refcount_decrement1(&zt->references);
|
||||
isc_refcount_decrement1(&zt->loads_pending);
|
||||
}
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -236,7 +236,7 @@ isc_httpdmgr_create(isc_nm_t *nm, isc_mem_t *mctx, isc_sockaddr_t *addr,
|
|||
|
||||
cleanup:
|
||||
httpdmgr->magic = 0;
|
||||
isc_refcount_decrement(&httpdmgr->references);
|
||||
isc_refcount_decrementz(&httpdmgr->references);
|
||||
isc_refcount_destroy(&httpdmgr->references);
|
||||
isc_mem_detach(&httpdmgr->mctx);
|
||||
isc_mutex_destroy(&httpdmgr->lock);
|
||||
|
|
|
|||
|
|
@ -133,4 +133,22 @@ isc_refcount_decrement(isc_refcount_t *target) {
|
|||
})
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
#define isc_refcount_decrementz(target) \
|
||||
do { \
|
||||
uint_fast32_t _refs = isc_refcount_decrement(target); \
|
||||
ISC_INSIST(_refs == 1); \
|
||||
} while (0)
|
||||
|
||||
#define isc_refcount_decrement1(target) \
|
||||
do { \
|
||||
uint_fast32_t _refs = isc_refcount_decrement(target); \
|
||||
ISC_INSIST(_refs > 1); \
|
||||
} while (0)
|
||||
|
||||
#define isc_refcount_decrement0(target) \
|
||||
do { \
|
||||
uint_fast32_t _refs = isc_refcount_decrement(target); \
|
||||
ISC_INSIST(_refs > 0); \
|
||||
} while (0)
|
||||
|
||||
ISC_LANG_ENDDECLS
|
||||
|
|
|
|||
|
|
@ -1015,7 +1015,7 @@ isc_mem_destroy(isc_mem_t **ctxp) {
|
|||
print_active(ctx, stderr);
|
||||
}
|
||||
#else /* if ISC_MEM_TRACKLINES */
|
||||
isc_refcount_decrement(&ctx->references);
|
||||
isc_refcount_decrementz(&ctx->references);
|
||||
#endif /* if ISC_MEM_TRACKLINES */
|
||||
isc_refcount_destroy(&ctx->references);
|
||||
destroy(ctx);
|
||||
|
|
|
|||
|
|
@ -2999,7 +2999,7 @@ internal_accept(isc__socket_t *sock) {
|
|||
inc_stats(manager->stats, sock->statsindex[STATID_ACCEPT]);
|
||||
} else {
|
||||
inc_stats(manager->stats, sock->statsindex[STATID_ACCEPTFAIL]);
|
||||
(void)isc_refcount_decrement(&NEWCONNSOCK(dev)->references);
|
||||
isc_refcount_decrementz(&NEWCONNSOCK(dev)->references);
|
||||
free_socket((isc__socket_t **)&dev->newsocket);
|
||||
}
|
||||
|
||||
|
|
@ -5081,7 +5081,7 @@ isc_socket_cancel(isc_socket_t *sock0, isc_task_t *task, unsigned int how) {
|
|||
ISC_LIST_UNLINK(sock->accept_list, dev,
|
||||
ev_link);
|
||||
|
||||
(void)isc_refcount_decrement(
|
||||
isc_refcount_decrementz(
|
||||
&NEWCONNSOCK(dev)->references);
|
||||
free_socket((isc__socket_t **)&dev->newsocket);
|
||||
|
||||
|
|
|
|||
|
|
@ -2488,7 +2488,7 @@ SocketIoThread(LPVOID ThreadContext) {
|
|||
closesocket(lpo->adev->newsocket->fd);
|
||||
lpo->adev->newsocket->fd =
|
||||
INVALID_SOCKET;
|
||||
isc_refcount_decrement(
|
||||
isc_refcount_decrementz(
|
||||
&lpo->adev->newsocket
|
||||
->references);
|
||||
free_socket(&lpo->adev->newsocket,
|
||||
|
|
@ -3501,7 +3501,7 @@ isc_socket_cancel(isc_socket_t *sock, isc_task_t *task, unsigned int how) {
|
|||
next = ISC_LIST_NEXT(dev, ev_link);
|
||||
|
||||
if ((task == NULL) || (task == current_task)) {
|
||||
isc_refcount_decrement(
|
||||
isc_refcount_decrementz(
|
||||
&dev->newsocket->references);
|
||||
closesocket(dev->newsocket->fd);
|
||||
dev->newsocket->fd = INVALID_SOCKET;
|
||||
|
|
|
|||
Loading…
Reference in a new issue