From: Raza Shafiq (rshafiq) Date: Thu, 7 Dec 2023 21:49:00 +0000 (+0000) Subject: Pull request #4133: host_cache: fix for race condition on peg counts X-Git-Tag: 3.1.77.0~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f611266f7a820b1f6771efd3d36550e742fc5f70;p=thirdparty%2Fsnort3.git Pull request #4133: host_cache: fix for race condition on peg counts Merge in SNORT/snort3 from ~RSHAFIQ/snort3:host_cache_pegs to master Squashed commit of the following: commit 2d742de0301f5940aa7f658336f382f33059f1e9 Author: rshafiq Date: Wed Dec 6 08:37:52 2023 -0500 host_cache: fix for race condition on peg counts --- diff --git a/src/host_tracker/host_cache_segmented.h b/src/host_tracker/host_cache_segmented.h index e80519262..fa01cce90 100644 --- a/src/host_tracker/host_cache_segmented.h +++ b/src/host_tracker/host_cache_segmented.h @@ -242,12 +242,16 @@ void HostCacheSegmented::update_counts() PegCount* pcs = (PegCount*)&counts; const PegInfo* pegs = get_pegs(); - for ( int i = 0; pegs[i].type != CountType::END; i++ ) + for (int i = 0; pegs[i].type != CountType::END; i++) + pcs[i] = 0; + + for (auto cache : seg_list) { - PegCount c = 0; - for(auto cache : seg_list) - c += cache->get_counts()[i]; - pcs[i] = c; + const PegCount* cache_counts = cache->get_counts(); + cache->lock(); + for (int i = 0; pegs[i].type != CountType::END; i++) + pcs[i] += cache_counts[i]; + cache->unlock(); } }