From 312bd133f75c54d51196060c573e29aabbb0b842 Mon Sep 17 00:00:00 2001
From: Mark Andrews <marka@isc.org>
Date: Tue, 26 Nov 2019 02:30:14 +0000
Subject: [PATCH 1/4] Merge branch
'1367-threadsanitizer-data-race-dispatch-c-901-in-free_buffer-v9_11' into
'v9_11'
Resolve "ThreadSanitizer: data race dispatch.c:901 in free_buffer"
See merge request isc-projects/bind9!2628
(cherry picked from commit 0455351802cb915e7961dad9cf14977a19162d38)
---
lib/dns/dispatch.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/lib/dns/dispatch.c b/lib/dns/dispatch.c
index 3278db4a07..ea5cf102f2 100644
--- a/lib/dns/dispatch.c
+++ b/lib/dns/dispatch.c
@@ -927,6 +927,10 @@ allocate_udp_buffer(dns_dispatch_t *disp) {
void *temp;
LOCK(&disp->mgr->buffer_lock);
+ if (disp->mgr->buffers >= disp->mgr->maxbuffers) {
+ UNLOCK(&disp->mgr->buffer_lock);
+ return (NULL);
+ }
bpool = disp->mgr->bpool;
disp->mgr->buffers++;
UNLOCK(&disp->mgr->buffer_lock);
@@ -1058,9 +1062,11 @@ udp_recv(isc_event_t *ev_in, dns_dispatch_t *disp, dispsocket_t *dispsock) {
mgr = disp->mgr;
qid = mgr->qid;
+ LOCK(&disp->mgr->buffer_lock);
dispatch_log(disp, LVL(90),
"got packet: requests %d, buffers %d, recvs %d",
disp->requests, disp->mgr->buffers, disp->recv_pending);
+ UNLOCK(&disp->mgr->buffer_lock);
if (dispsock == NULL && ev->ev_type == ISC_SOCKEVENT_RECVDONE) {
/*
@@ -1511,9 +1517,6 @@ startrecv(dns_dispatch_t *disp, dispsocket_t *dispsock) {
if (disp->recv_pending != 0 && dispsock == NULL)
return (ISC_R_SUCCESS);
- if (disp->mgr->buffers >= disp->mgr->maxbuffers)
- return (ISC_R_NOMEMORY);
-
if ((disp->attributes & DNS_DISPATCHATTR_EXCLUSIVE) != 0 &&
dispsock == NULL)
return (ISC_R_SUCCESS);
--
2.21.0