diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2011-05-03 09:41:35 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2011-05-03 09:41:35 +0200 |
commit | 678a904620222b9113db8b5f89e988a064b05cd9 (patch) | |
tree | afe63a0170fd0402a80b494abcfb49093287690a /runtime | |
parent | 921bebc8ee203c0569332c636515c4de036dfcf9 (diff) | |
download | rsyslog-678a904620222b9113db8b5f89e988a064b05cd9.tar.gz rsyslog-678a904620222b9113db8b5f89e988a064b05cd9.tar.xz rsyslog-678a904620222b9113db8b5f89e988a064b05cd9.zip |
bugfix: memory and file descriptor leak in stream processing
Leaks could occur under some circumstances if the file stream handler
errored out during the open call. Among others, this could cause very
big memory leaks if there were a problem with unreadable disk queue
files. In regard to the memory leak, this
closes: http://bugzilla.adiscon.com/show_bug.cgi?id=256
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/stream.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/runtime/stream.c b/runtime/stream.c index af38bcb7..a12dda41 100644 --- a/runtime/stream.c +++ b/runtime/stream.c @@ -258,6 +258,7 @@ static rsRetVal strmOpenFile(strm_t *pThis) if(pThis->fd != -1) ABORT_FINALIZE(RS_RET_OK); + pThis->pszCurrFName = NULL; /* used to prevent mem leak in case of error */ if(pThis->pszFName == NULL) ABORT_FINALIZE(RS_RET_FILE_PREFIX_MISSING); @@ -289,6 +290,16 @@ static rsRetVal strmOpenFile(strm_t *pThis) (pThis->tOperationsMode == STREAMMODE_READ) ? "READ" : "WRITE", pThis->fd); finalize_it: + if(iRet != RS_RET_OK) { + if(pThis->pszCurrFName != NULL) { + free(pThis->pszCurrFName); + pThis->pszCurrFName = NULL; /* just to prevent mis-adressing down the road... */ + } + if(pThis->fd != -1) { + close(pThis->fd); + pThis->fd = -1; + } + } RETiRet; } |