diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2009-06-25 15:21:29 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2009-06-25 15:21:29 +0200 |
commit | 4818b0081d3a265a87f9f646d79f2a2ffbcda819 (patch) | |
tree | a9edb0a994fec151300e9c11faf71356ddb7e3c7 /runtime/msg.c | |
parent | d116f30a877c65b4f23dbb92601251402b0f957e (diff) | |
download | rsyslog-4818b0081d3a265a87f9f646d79f2a2ffbcda819.tar.gz rsyslog-4818b0081d3a265a87f9f646d79f2a2ffbcda819.tar.bz2 rsyslog-4818b0081d3a265a87f9f646d79f2a2ffbcda819.zip |
bugfix: subtle synchronization issue
This may have caused a segfault under strange circumstances (but if
we just run long enough with a high enough message volume, even the
strangest circumstances will occur...)
Diffstat (limited to 'runtime/msg.c')
-rw-r--r-- | runtime/msg.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/runtime/msg.c b/runtime/msg.c index 8aab5317..a1a4714f 100644 --- a/runtime/msg.c +++ b/runtime/msg.c @@ -607,10 +607,12 @@ CODESTARTobjDestruct(msg) * operations on the counter. --- rgerhards, 2009-06-22. */ # if HAVE_MALLOC_TRIM - { /* standard C requires a new block for a new variable definition! */ + { /* standard C requires a new block for a new variable definition! + * To simplify matters, we use modulo arithmetic and live with the fact + * that we trim too often when the counter wraps. + */ static unsigned iTrimCtr = 1; - if(iTrimCtr ++ % 100000 == 0) { - iTrimCtr = 1; + if(ATOMIC_INC_AND_FETCH(iTrimCtr) % 100000 == 0) { malloc_trim(128*1024); } } |