Fix some race conditions by using atomic operations. (#1420)

Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
This commit is contained in:
Toni
2022-01-29 09:18:51 +01:00
committed by GitHub
parent 0c70411b1b
commit 9b8679a320
2 changed files with 11 additions and 13 deletions
+3 -3
View File
@@ -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);