summaryrefslogtreecommitdiffstats
path: root/runtime/msg.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-09-19 17:41:11 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2008-09-19 17:41:11 +0200
commitbc70a730194759e85f9c3641573c46b4a8476198 (patch)
tree91dc51ac59a8ed32b83afdff777c80578e050030 /runtime/msg.c
parent4c96ebdcfe075e80810b01257cf21ea1c9b3ec0e (diff)
downloadrsyslog-bc70a730194759e85f9c3641573c46b4a8476198.tar.gz
rsyslog-bc70a730194759e85f9c3641573c46b4a8476198.tar.xz
rsyslog-bc70a730194759e85f9c3641573c46b4a8476198.zip
bugfix: proper synchronization on message destruction
The code was potentially race, at least on systems where a memory barrier was needed. Fix not fully tested yet.
Diffstat (limited to 'runtime/msg.c')
-rw-r--r--runtime/msg.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/runtime/msg.c b/runtime/msg.c
index f4eb9414..346bbc5f 100644
--- a/runtime/msg.c
+++ b/runtime/msg.c
@@ -276,8 +276,10 @@ CODESTARTobjDestruct(msg)
# ifdef DO_HAVE_ATOMICS
currRefCount = ATOMIC_DEC_AND_FETCH(pThis->iRefCount);
# else
+ MsgLock(pThis);
currRefCount = --pThis->iRefCount;
# endif
+// we need a mutex, because we may be suspended after getting the refcount but before
if(currRefCount == 0)
{
/* DEV Debugging Only! dbgprintf("msgDestruct\t0x%lx, RefCount now 0, doing DESTROY\n", (unsigned long)pThis); */
@@ -337,9 +339,11 @@ CODESTARTobjDestruct(msg)
rsCStrDestruct(&pThis->pCSPROCID);
if(pThis->pCSMSGID != NULL)
rsCStrDestruct(&pThis->pCSMSGID);
+ MsgUnlock(pThis);
funcDeleteMutex(pThis);
} else {
pThis = NULL; /* tell framework not to destructing the object! */
+ MsgUnlock(pThis);
}
ENDobjDestruct(msg)