]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Address data race in dns_stats_detach over references
authorMark Andrews <marka@isc.org>
Thu, 15 Oct 2020 05:48:24 +0000 (16:48 +1100)
committerMark Andrews <marka@isc.org>
Thu, 10 Dec 2020 06:31:19 +0000 (06:31 +0000)
    WARNING: ThreadSanitizer: data race
    Write of size 4 at 0x000000000001 by thread T1 (mutexes: write M1):
    #0 dns_stats_detach lib/dns/stats.c:115:19
    #1 destroy lib/dns/view.c:527:3
    #2 dns_view_weakdetach lib/dns/view.c:704:3
    #3 zone_free lib/dns/zone.c:1149:3
    #4 zone_shutdown lib/dns/zone.c:13123:3
    #5 dispatch lib/isc/task.c:1157:7
    #6 run lib/isc/task.c:1331:2

    Previous read of size 4 at 0x000000000001 by thread T2:
    #0 dns_stats_detach lib/dns/stats.c:118:13
    #1 destroy lib/dns/view.c:527:3
    #2 dns_view_weakdetach lib/dns/view.c:704:3
    #3 zone_free lib/dns/zone.c:1152:3
    #4 zone_shutdown lib/dns/zone.c:13123:3
    #5 dispatch lib/isc/task.c:1157:7
    #6 run lib/isc/task.c:1331:2

lib/dns/stats.c

index 1473371c644e036f4f3c48709a99d1c21a975803..a0184ecf84d7647f86bdf408e76791c2a1b21f18 100644 (file)
@@ -104,6 +104,7 @@ dns_stats_attach(dns_stats_t *stats, dns_stats_t **statsp) {
 
 void
 dns_stats_detach(dns_stats_t **statsp) {
+       unsigned int references;
        dns_stats_t *stats;
 
        REQUIRE(statsp != NULL && DNS_STATS_VALID(*statsp));
@@ -112,10 +113,10 @@ dns_stats_detach(dns_stats_t **statsp) {
        *statsp = NULL;
 
        LOCK(&stats->lock);
-       stats->references--;
+       references = --stats->references;
        UNLOCK(&stats->lock);
 
-       if (stats->references == 0) {
+       if (references == 0) {
                isc_stats_detach(&stats->counters);
                DESTROYLOCK(&stats->lock);
                isc_mem_putanddetach(&stats->mctx, stats, sizeof(*stats));