diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2010-03-08 14:27:20 +0100 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2010-03-08 14:27:20 +0100 |
commit | 06387e5592ffb4f7b20ea631f0824ff2cc652c20 (patch) | |
tree | dc964b62013bf67dc18c73d3fc1f3a97e931fed0 /tools/omfile.c | |
parent | b4cdb7c997eee95df96321d11d03cf90e4a6caba (diff) | |
parent | 0b84d47f7a244c25f63fadcec92d12ebfbe319a4 (diff) | |
download | rsyslog-06387e5592ffb4f7b20ea631f0824ff2cc652c20.tar.gz rsyslog-06387e5592ffb4f7b20ea631f0824ff2cc652c20.tar.xz rsyslog-06387e5592ffb4f7b20ea631f0824ff2cc652c20.zip |
Merge branch 'v4-stable' into beta
Conflicts:
ChangeLog
configure.ac
doc/manual.html
tests/rt-init.c
Diffstat (limited to 'tools/omfile.c')
-rw-r--r-- | tools/omfile.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/tools/omfile.c b/tools/omfile.c index 2499680d..5b672181 100644 --- a/tools/omfile.c +++ b/tools/omfile.c @@ -345,6 +345,7 @@ dynaFileFreeCacheEntries(instanceData *pData) for(i = 0 ; i < pData->iCurrCacheSize ; ++i) { dynaFileDelCacheEntry(pData->dynCache, i, 1); } + pData->iCurrElt = -1; /* invalidate current element */ ENDfunc; } @@ -528,6 +529,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++; @@ -559,7 +568,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; @@ -812,7 +825,6 @@ BEGINdoHUP CODESTARTdoHUP if(pData->bDynamicName) { dynaFileFreeCacheEntries(pData); - pData->iCurrElt = -1; /* invalidate current element */ } else { if(pData->pStrm != NULL) { strm.Destruct(&pData->pStrm); |