summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBojan Smojver <bojan@rexursive.com>2011-03-04 07:55:53 +0100
committerRainer Gerhards <rgerhards@adiscon.com>2011-03-04 07:55:53 +0100
commit87f8ac6dc4343eb4664ca5e234c163c399afca1b (patch)
treeabd1301e50e80dd6f6ca0cfafa276e3450372fd7
parentd1eb6e0edc51a78f3209448e800b25eda50340f2 (diff)
downloadrsyslog-87f8ac6dc4343eb4664ca5e234c163c399afca1b.tar.gz
rsyslog-87f8ac6dc4343eb4664ca5e234c163c399afca1b.tar.xz
rsyslog-87f8ac6dc4343eb4664ca5e234c163c399afca1b.zip
bugfix: regression: memory leak in module loader
Signed-off-by: Rainer Gerhards <rgerhards@adiscon.com>
-rw-r--r--runtime/modules.c28
-rw-r--r--runtime/modules.h6
2 files changed, 21 insertions, 13 deletions
diff --git a/runtime/modules.c b/runtime/modules.c
index 86e7c695..4541bddf 100644
--- a/runtime/modules.c
+++ b/runtime/modules.c
@@ -545,18 +545,26 @@ doModInit(rsRetVal (*modInit)(int, int*, rsRetVal(**)(), rsRetVal(*)(), modInfo_
/* if we need to keep the linked module, save it */
if (pNew->eKeepType == eMOD_KEEP) {
- if((pHandle = calloc(1, sizeof (*pHandle))) == NULL) {
- iRet = RS_RET_OUT_OF_MEMORY;
- goto finalize_it;
+ /* see if we have this one already */
+ for (pHandle = pHandles; pHandle; pHandle = pHandle->next) {
+ if (!strcmp((char *)name, (char *)pHandle->pszName))
+ break;
}
- strncpy((char *)pHandle->szName,
- (char *)name, PATH_MAX - 1);
- pHandle->szName[PATH_MAX - 1] = '\0';
- pHandle->pModHdlr = pModHdlr;
- pHandle->next = pHandles;
+ /* not found, create it */
+ if (!pHandle) {
+ if((pHandle = malloc(sizeof (*pHandle))) == NULL) {
+ ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
+ }
+ if((pHandle->pszName = (uchar*) strdup((char*)name)) == NULL) {
+ free(pHandle);
+ ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
+ }
+ pHandle->pModHdlr = pModHdlr;
+ pHandle->next = pHandles;
- pHandles = pHandle;
+ pHandles = pHandle;
+ }
}
}
@@ -859,7 +867,7 @@ Load(uchar *pModName)
/* see if we have this one already */
for (pHandle = pHandles; pHandle; pHandle = pHandle->next) {
- if (!strcmp((char *)pModName, (char *)pHandle->szName)) {
+ if (!strcmp((char *)pModName, (char *)pHandle->pszName)) {
pModHdlr = pHandle->pModHdlr;
break;
}
diff --git a/runtime/modules.h b/runtime/modules.h
index 7eff8581..4daaf1f9 100644
--- a/runtime/modules.h
+++ b/runtime/modules.h
@@ -77,9 +77,9 @@ typedef enum eModLinkType_ {
/* remember which shared libs we dlopen()-ed */
struct dlhandle_s {
- uchar szName[PATH_MAX];
- void *pModHdlr;
- struct dlhandle_s *next;
+ uchar *pszName;
+ void *pModHdlr;
+ struct dlhandle_s *next;
};
/* should this module be kept linked? */