From dd06002fad633e75bfedaaa5c83e7ce396e7e11e Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Thu, 27 Jan 2022 13:56:06 +0100 Subject: Fix some race conditions by using atomic operations. Signed-off-by: Toni Uhlig --- src/lib/ndpi_main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/lib/ndpi_main.c') diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c index e4106d58d..9f4a04232 100644 --- a/src/lib/ndpi_main.c +++ b/src/lib/ndpi_main.c @@ -145,13 +145,13 @@ static u_int32_t ndpi_tot_allocated_memory; /* ****************************************** */ u_int32_t ndpi_get_tot_allocated_memory() { - return(ndpi_tot_allocated_memory); + return(__sync_fetch_and_add(&ndpi_tot_allocated_memory, 0)); } /* ****************************************** */ void *ndpi_malloc(size_t size) { - ndpi_tot_allocated_memory += size; + __sync_fetch_and_add(&ndpi_tot_allocated_memory, size); return(_ndpi_malloc ? _ndpi_malloc(size) : malloc(size)); } @@ -169,7 +169,7 @@ void *ndpi_calloc(unsigned long count, size_t size) { if(p) { memset(p, 0, len); - ndpi_tot_allocated_memory += size; + __sync_fetch_and_add(&ndpi_tot_allocated_memory, size); } return(p); -- cgit v1.2.3