aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorToni <matzeton@googlemail.com>2022-01-29 09:18:51 +0100
committerGitHub <noreply@github.com>2022-01-29 09:18:51 +0100
commit9b8679a320c3c210d9e3fda2c1ee8049d2b6c79f (patch)
treec0f4fbe5d2d9bab1b4a19b1639dbd64dd4bfc85e /src/lib
parent0c70411b1b093279f3d7c09b2b57b491911df84c (diff)
Fix some race conditions by using atomic operations. (#1420)
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ndpi_main.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c
index 54f03916d..3cfc2b2ce 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);