Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/external/mpl/bind/dist/lib/dns/client.c,v rcsdiff: /ftp/cvs/cvsroot/src/external/mpl/bind/dist/lib/dns/client.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.4 retrieving revision 1.5 diff -u -p -r1.4 -r1.5 --- src/external/mpl/bind/dist/lib/dns/client.c 2019/04/28 00:01:14 1.4 +++ src/external/mpl/bind/dist/lib/dns/client.c 2019/09/05 19:32:58 1.5 @@ -1,4 +1,4 @@ -/* $NetBSD: client.c,v 1.4 2019/04/28 00:01:14 christos Exp $ */ +/* $NetBSD: client.c,v 1.5 2019/09/05 19:32:58 christos Exp $ */ /* * Copyright (C) Internet Systems Consortium, Inc. ("ISC") @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -96,8 +97,9 @@ struct dns_client { unsigned int find_timeout; unsigned int find_udpretries; + isc_refcount_t references; + /* Locked */ - unsigned int references; dns_viewlist_t viewlist; ISC_LIST(struct resctx) resctxs; ISC_LIST(struct reqctx) reqctxs; @@ -125,10 +127,10 @@ typedef struct resctx { unsigned int magic; isc_mutex_t lock; dns_client_t *client; - bool want_dnssec; - bool want_validation; - bool want_cdflag; - bool want_tcp; + bool want_dnssec; + bool want_validation; + bool want_cdflag; + bool want_tcp; /* Locked */ ISC_LINK(struct resctx) link; @@ -141,7 +143,7 @@ typedef struct resctx { dns_namelist_t namelist; isc_result_t result; dns_clientresevent_t *event; - bool canceled; + bool canceled; dns_rdataset_t *rdataset; dns_rdataset_t *sigrdataset; } resctx_t; @@ -160,7 +162,7 @@ typedef struct resarg { isc_result_t vresult; dns_namelist_t *namelist; dns_clientrestrans_t *trans; - bool canceled; + bool canceled; } resarg_t; /*% @@ -175,7 +177,7 @@ typedef struct reqctx { /* Locked */ ISC_LINK(struct reqctx) link; - bool canceled; + bool canceled; dns_tsigkey_t *tsigkey; dns_request_t *request; dns_clientreqevent_t *event; @@ -193,7 +195,7 @@ typedef struct reqarg { /* Locked */ isc_result_t result; dns_clientreqtrans_t *trans; - bool canceled; + bool canceled; } reqarg_t; /*% @@ -208,7 +210,7 @@ typedef struct updatearg { /* Locked */ isc_result_t result; dns_clientupdatetrans_t *trans; - bool canceled; + bool canceled; } updatearg_t; /*% @@ -219,14 +221,14 @@ typedef struct updatectx { unsigned int magic; isc_mutex_t lock; dns_client_t *client; - bool want_tcp; + bool want_tcp; /* Locked */ dns_request_t *updatereq; dns_request_t *soareq; dns_clientrestrans_t *restrans; dns_clientrestrans_t *restrans2; - bool canceled; + bool canceled; /* Task Locked */ ISC_LINK(struct updatectx) link; @@ -504,12 +506,13 @@ dns_client_createx(isc_mem_t *mctx, isc_ client->task = NULL; result = isc_task_create(client->taskmgr, 0, &client->task); - if (result != ISC_R_SUCCESS) - goto cleanup; + if (result != ISC_R_SUCCESS) { + goto cleanup_lock; + } result = dns_dispatchmgr_create(mctx, &dispatchmgr); if (result != ISC_R_SUCCESS) - goto cleanup; + goto cleanup_task; client->dispatchmgr = dispatchmgr; (void)setsourceports(mctx, dispatchmgr); @@ -522,8 +525,9 @@ dns_client_createx(isc_mem_t *mctx, isc_ result = getudpdispatch(AF_INET, dispatchmgr, socketmgr, taskmgr, true, &dispatchv4, localaddr4); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { client->dispatchv4 = dispatchv4; + } } client->dispatchv6 = NULL; @@ -531,22 +535,27 @@ dns_client_createx(isc_mem_t *mctx, isc_ result = getudpdispatch(AF_INET6, dispatchmgr, socketmgr, taskmgr, true, &dispatchv6, localaddr6); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { client->dispatchv6 = dispatchv6; + } } /* We need at least one of the dispatchers */ if (dispatchv4 == NULL && dispatchv6 == NULL) { INSIST(result != ISC_R_SUCCESS); - goto cleanup; + goto cleanup_dispatchmgr; } + isc_refcount_init(&client->references, 1); + /* Create the default view for class IN */ result = createview(mctx, dns_rdataclass_in, options, taskmgr, RESOLVER_NTASKS, socketmgr, timermgr, dispatchmgr, dispatchv4, dispatchv6, &view); - if (result != ISC_R_SUCCESS) - goto cleanup; + if (result != ISC_R_SUCCESS) { + goto cleanup_references; + } + ISC_LIST_INIT(client->viewlist); ISC_LIST_APPEND(client->viewlist, view, link); @@ -566,32 +575,38 @@ dns_client_createx(isc_mem_t *mctx, isc_ client->find_udpretries = DEF_FIND_UDPRETRIES; client->attributes = 0; - client->references = 1; client->magic = DNS_CLIENT_MAGIC; *clientp = client; return (ISC_R_SUCCESS); - cleanup: - if (dispatchv4 != NULL) + cleanup_references: + isc_refcount_decrement(&client->references); + isc_refcount_destroy(&client->references); + cleanup_dispatchmgr: + if (dispatchv4 != NULL) { dns_dispatch_detach(&dispatchv4); - if (dispatchv6 != NULL) + } + if (dispatchv6 != NULL) { dns_dispatch_detach(&dispatchv6); - if (dispatchmgr != NULL) - dns_dispatchmgr_destroy(&dispatchmgr); - if (client->task != NULL) - isc_task_detach(&client->task); + } + dns_dispatchmgr_destroy(&dispatchmgr); + cleanup_task: + isc_task_detach(&client->task); + cleanup_lock: + isc_mutex_destroy(&client->lock); isc_mem_put(mctx, client, sizeof(*client)); return (result); } static void -destroyclient(dns_client_t **clientp) { - dns_client_t *client = *clientp; +destroyclient(dns_client_t *client) { dns_view_t *view; + isc_refcount_destroy(&client->references); + while ((view = ISC_LIST_HEAD(client->viewlist)) != NULL) { ISC_LIST_UNLINK(client->viewlist, view, link); dns_view_detach(&view); @@ -623,32 +638,20 @@ destroyclient(dns_client_t **clientp) { client->magic = 0; isc_mem_putanddetach(&client->mctx, client, sizeof(*client)); - - *clientp = NULL; } void dns_client_destroy(dns_client_t **clientp) { dns_client_t *client; - bool destroyok = false; REQUIRE(clientp != NULL); client = *clientp; + *clientp = NULL; REQUIRE(DNS_CLIENT_VALID(client)); - LOCK(&client->lock); - client->references--; - if (client->references == 0 && ISC_LIST_EMPTY(client->resctxs) && - ISC_LIST_EMPTY(client->reqctxs) && - ISC_LIST_EMPTY(client->updatectxs)) { - destroyok = true; + if (isc_refcount_decrement(&client->references) == 1) { + destroyclient(client); } - UNLOCK(&client->lock); - - if (destroyok) - destroyclient(&client); - - *clientp = NULL; } isc_result_t @@ -1098,6 +1101,12 @@ client_resfind(resctx_t *rctx, dns_fetch } } } + if (rctx->rdataset != NULL) { + putrdataset(mctx, &rctx->rdataset); + } + if (rctx->sigrdataset != NULL) { + putrdataset(mctx, &rctx->sigrdataset); + } if (n == 0) { /* * We didn't match any rdatasets (which means @@ -1432,6 +1441,7 @@ dns_client_startresolve(dns_client_t *cl rctx->event = event; rctx->magic = RCTX_MAGIC; + isc_refcount_increment(&client->references); LOCK(&client->lock); ISC_LIST_APPEND(client->resctxs, rctx, link); @@ -1502,10 +1512,10 @@ dns_client_destroyrestrans(dns_clientres resctx_t *rctx; isc_mem_t *mctx; dns_client_t *client; - bool need_destroyclient = false; REQUIRE(transp != NULL); rctx = (resctx_t *)*transp; + *transp = NULL; REQUIRE(RCTX_VALID(rctx)); REQUIRE(rctx->fetch == NULL); REQUIRE(rctx->event == NULL); @@ -1527,11 +1537,6 @@ dns_client_destroyrestrans(dns_clientres INSIST(ISC_LINK_LINKED(rctx, link)); ISC_LIST_UNLINK(client->resctxs, rctx, link); - if (client->references == 0 && ISC_LIST_EMPTY(client->resctxs) && - ISC_LIST_EMPTY(client->reqctxs) && - ISC_LIST_EMPTY(client->updatectxs)) - need_destroyclient = true; - UNLOCK(&client->lock); INSIST(ISC_LIST_EMPTY(rctx->namelist)); @@ -1541,10 +1546,8 @@ dns_client_destroyrestrans(dns_clientres isc_mem_put(mctx, rctx, sizeof(*rctx)); - if (need_destroyclient) - destroyclient(&client); + dns_client_destroy(&client); - *transp = NULL; } isc_result_t @@ -1810,6 +1813,7 @@ dns_client_startrequest(dns_client_t *cl LOCK(&client->lock); ISC_LIST_APPEND(client->reqctxs, ctx, link); + isc_refcount_increment(&client->references); UNLOCK(&client->lock); ctx->request = NULL; @@ -1824,6 +1828,8 @@ dns_client_startrequest(dns_client_t *cl return (ISC_R_SUCCESS); } + isc_refcount_decrement(&client->references); + cleanup: if (ctx != NULL) { LOCK(&client->lock); @@ -1864,10 +1870,10 @@ dns_client_destroyreqtrans(dns_clientreq reqctx_t *ctx; isc_mem_t *mctx; dns_client_t *client; - bool need_destroyclient = false; REQUIRE(transp != NULL); ctx = (reqctx_t *)*transp; + *transp = NULL; REQUIRE(REQCTX_VALID(ctx)); client = ctx->client; REQUIRE(DNS_CLIENT_VALID(client)); @@ -1882,12 +1888,6 @@ dns_client_destroyreqtrans(dns_clientreq INSIST(ISC_LINK_LINKED(ctx, link)); ISC_LIST_UNLINK(client->reqctxs, ctx, link); - if (client->references == 0 && ISC_LIST_EMPTY(client->resctxs) && - ISC_LIST_EMPTY(client->reqctxs) && - ISC_LIST_EMPTY(client->updatectxs)) { - need_destroyclient = true; - } - UNLOCK(&client->lock); isc_mutex_destroy(&ctx->lock); @@ -1895,10 +1895,7 @@ dns_client_destroyreqtrans(dns_clientreq isc_mem_put(mctx, ctx, sizeof(*ctx)); - if (need_destroyclient) - destroyclient(&client); - - *transp = NULL; + dns_client_destroy(&client); } /*% @@ -2984,6 +2981,7 @@ dns_client_startupdate(dns_client_t *cli LOCK(&client->lock); ISC_LIST_APPEND(client->updatectxs, uctx, link); + isc_refcount_increment(&client->references); UNLOCK(&client->lock); *transp = (dns_clientupdatetrans_t *)uctx; @@ -3002,6 +3000,8 @@ dns_client_startupdate(dns_client_t *cli } if (result == ISC_R_SUCCESS) return (result); + + isc_refcount_decrement(&client->references); *transp = NULL; fail: @@ -3059,11 +3059,11 @@ dns_client_destroyupdatetrans(dns_client updatectx_t *uctx; isc_mem_t *mctx; dns_client_t *client; - bool need_destroyclient = false; isc_sockaddr_t *sa; REQUIRE(transp != NULL); uctx = (updatectx_t *)*transp; + *transp = NULL; REQUIRE(UCTX_VALID(uctx)); client = uctx->client; REQUIRE(DNS_CLIENT_VALID(client)); @@ -3084,11 +3084,6 @@ dns_client_destroyupdatetrans(dns_client INSIST(ISC_LINK_LINKED(uctx, link)); ISC_LIST_UNLINK(client->updatectxs, uctx, link); - if (client->references == 0 && ISC_LIST_EMPTY(client->resctxs) && - ISC_LIST_EMPTY(client->reqctxs) && - ISC_LIST_EMPTY(client->updatectxs)) - need_destroyclient = true; - UNLOCK(&client->lock); isc_mutex_destroy(&uctx->lock); @@ -3096,10 +3091,7 @@ dns_client_destroyupdatetrans(dns_client isc_mem_put(mctx, uctx, sizeof(*uctx)); - if (need_destroyclient) - destroyclient(&client); - - *transp = NULL; + dns_client_destroy(&client); } isc_mem_t *