summaryrefslogtreecommitdiffstats
path: root/tools/omfile.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2010-03-09 14:28:30 +0100
committerRainer Gerhards <rgerhards@adiscon.com>2010-03-09 14:28:30 +0100
commitc802afb7e0fc5e2c87af24e12bf63e4a0ba7688c (patch)
tree107991afae384af32c95be306c86f387ea67083b /tools/omfile.c
parent81c9cf86267fb0ec1156e578439d09499c97e80f (diff)
parentde7726cbf0957384cc9261ac47d6bf65906739b5 (diff)
downloadrsyslog-c802afb7e0fc5e2c87af24e12bf63e4a0ba7688c.tar.gz
rsyslog-c802afb7e0fc5e2c87af24e12bf63e4a0ba7688c.tar.xz
rsyslog-c802afb7e0fc5e2c87af24e12bf63e4a0ba7688c.zip
Merge branch 'v5-stable'
Conflicts: ChangeLog configure.ac doc/manual.html doc/property_replacer.html runtime/datetime.h
Diffstat (limited to 'tools/omfile.c')
-rw-r--r--tools/omfile.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/tools/omfile.c b/tools/omfile.c
index 1f203852..9562e9cf 100644
--- a/tools/omfile.c
+++ b/tools/omfile.c
@@ -364,6 +364,7 @@ dynaFileFreeCacheEntries(instanceData *pData)
for(i = 0 ; i < pData->iCurrCacheSize ; ++i) {
dynaFileDelCacheEntry(pData->dynCache, i, 1);
}
+ pData->iCurrElt = -1; /* invalidate current element */
ENDfunc;
}
@@ -547,6 +548,14 @@ prepareDynFile(instanceData *pData, uchar *newFileName, unsigned iMsgOpts)
}
/* we have not found an entry */
+
+ /* invalidate iCurrElt as we may error-exit out of this function when the currrent
+ * iCurrElt has been freed or otherwise become unusable. This is a precaution, and
+ * performance-wise it may be better to do that in each of the exits. However, that
+ * is error-prone, so I prefer to do it here. -- rgerhards, 2010-03-02
+ */
+ pData->iCurrElt = -1;
+
if(iFirstFree == -1 && (pData->iCurrCacheSize < pData->iDynaFileCacheSize)) {
/* there is space left, so set it to that index */
iFirstFree = pData->iCurrCacheSize++;
@@ -578,7 +587,11 @@ prepareDynFile(instanceData *pData, uchar *newFileName, unsigned iMsgOpts)
ABORT_FINALIZE(localRet);
}
- CHKmalloc(pCache[iFirstFree]->pName = ustrdup(newFileName));
+ if((pCache[iFirstFree]->pName = ustrdup(newFileName)) == NULL) {
+ /* we need to discard the entry, otherwise things could lead to a segfault! */
+ dynaFileDelCacheEntry(pCache, iFirstFree, 1);
+ ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
+ }
pCache[iFirstFree]->pStrm = pData->pStrm;
pCache[iFirstFree]->clkTickAccessed = getClockFileAccess();
pData->iCurrElt = iFirstFree;
@@ -831,7 +844,6 @@ BEGINdoHUP
CODESTARTdoHUP
if(pData->bDynamicName) {
dynaFileFreeCacheEntries(pData);
- pData->iCurrElt = -1; /* invalidate current element */
} else {
if(pData->pStrm != NULL) {
strm.Destruct(&pData->pStrm);