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

Refactored dns_message_t for using attach/detach semantics

This commit will be used as a base for the next code updates in order
to have a better control of dns_message_t objects' lifetime.
This commit is contained in:
Diego Fronza
2020-09-21 16:16:15 -03:00
committed by Ondřej Surý
parent e6f2f79ff2
commit 12d6d13100
26 changed files with 142 additions and 115 deletions

View File

@@ -539,7 +539,7 @@ msgresetsigs(dns_message_t *msg, bool replying) {
/*
* Free all but one (or everything) for this message. This is used by
* both dns_message_reset() and dns_message_destroy().
* both dns_message_reset() and dns__message_destroy().
*/
static void
msgreset(dns_message_t *msg, bool everything) {
@@ -774,6 +774,8 @@ dns_message_create(isc_mem_t *mctx, unsigned int intent, dns_message_t **msgp) {
m->cctx = NULL;
isc_refcount_init(&m->refcount, 1);
*msgp = m;
return (ISC_R_SUCCESS);
}
@@ -788,23 +790,38 @@ dns_message_reset(dns_message_t *msg, unsigned int intent) {
msg->from_to_wire = intent;
}
void
dns_message_destroy(dns_message_t **msgp) {
dns_message_t *msg;
REQUIRE(msgp != NULL);
REQUIRE(DNS_MESSAGE_VALID(*msgp));
msg = *msgp;
*msgp = NULL;
static void
dns__message_destroy(dns_message_t *msg) {
REQUIRE(msg != NULL);
REQUIRE(DNS_MESSAGE_VALID(msg));
msgreset(msg, true);
isc_mempool_destroy(&msg->namepool);
isc_mempool_destroy(&msg->rdspool);
isc_refcount_destroy(&msg->refcount);
msg->magic = 0;
isc_mem_putanddetach(&msg->mctx, msg, sizeof(dns_message_t));
}
void
dns_message_attach(dns_message_t *source, dns_message_t **target) {
REQUIRE(DNS_MESSAGE_VALID(source));
isc_refcount_increment(&source->refcount);
*target = source;
}
void
dns_message_detach(dns_message_t **messagep) {
REQUIRE(messagep != NULL && DNS_MESSAGE_VALID(*messagep));
dns_message_t *msg = *messagep;
*messagep = NULL;
if (isc_refcount_decrement(&msg->refcount) == 1) {
dns__message_destroy(msg);
}
}
static isc_result_t
findname(dns_name_t **foundname, const dns_name_t *target,
dns_namelist_t *section) {