summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2009-09-24 16:05:40 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2009-09-24 16:05:40 +0200
commitd15eb7fa83fc4ed237a6e692b7a5e3648038333a (patch)
treec3956591aa214557a0672fd73a82555d480d3e29
parenteb9da005ba2d21e2f0b2a8ad23ad925d7d628a15 (diff)
downloadrsyslog-d15eb7fa83fc4ed237a6e692b7a5e3648038333a.tar.gz
rsyslog-d15eb7fa83fc4ed237a6e692b7a5e3648038333a.tar.xz
rsyslog-d15eb7fa83fc4ed237a6e692b7a5e3648038333a.zip
bugfix: this morning's race patch was incomplete, completing now
we needed to release ALL resources (including file handles!) only after the the async writer thread has terminated (else it may access them). In this case, we had a file handle leak, because the handle was sometimes only opened in the async writer, but the close was attempted before the writer even started (in some cases).
-rw-r--r--runtime/stream.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/runtime/stream.c b/runtime/stream.c
index ff4515fc..3348fb74 100644
--- a/runtime/stream.c
+++ b/runtime/stream.c
@@ -677,14 +677,11 @@ CODESTARTobjDestruct(strm)
/* Note: mutex will be unlocked in stopWriter! */
d_pthread_mutex_lock(&pThis->mut);
+dbgprintf("XXX: destruct stream 1 %p\n", pThis);
if(pThis->tOperationsMode != STREAMMODE_READ)
strmFlush(pThis);
-dbgprintf("XXX: destruct stream %p\n", pThis);
- /* ... then free resources */
- if(pThis->fd != -1)
- strmCloseFile(pThis);
-
+dbgprintf("XXX: destruct stream 2 %p\n", pThis);
if(pThis->bAsyncWrite) {
stopWriter(pThis);
pthread_mutex_destroy(&pThis->mut);
@@ -697,10 +694,15 @@ dbgprintf("XXX: destruct stream %p\n", pThis);
} else {
free(pThis->pIOBuf);
}
+dbgprintf("XXX: destruct stream 3 (doing close) %p\n", pThis);
- /* IMPORTANT: we MUST free this only AFTER the ansyncWriter has been stopped, else
+ /* Finally, we can free the resources.
+ * IMPORTANT: we MUST free this only AFTER the ansyncWriter has been stopped, else
* we get random errors...
*/
+ if(pThis->fd != -1)
+ strmCloseFile(pThis);
+
free(pThis->pszDir);
free(pThis->pZipBuf);
free(pThis->pszCurrFName);