rsyslog/backport-fix-memory-leak-in-afterRun-Code.patch
2022-12-30 17:05:24 +08:00

97 lines
3.2 KiB
Diff

From 1ac3312e5a1e809158a0cccd5a332d3a67562a4f Mon Sep 17 00:00:00 2001
From: Andre lorbach <alorbach@adiscon.com>
Date: Mon, 22 Nov 2021 23:08:08 +0100
Subject: [PATCH] imtcp: fix memory leak in afterRun Code
- tcpsrv_etry_t was left in memory, is now freed
- Fix copy&paste error for pszLstnPortFileName init
- Free cnf_params if createInstance init fails
closes: https://github.com/rsyslog/rsyslog/issues/4646
Conflict:NA
Reference:https://github.com/rsyslog/rsyslog/commit/1ac3312e5a1e809158a0cccd5a332d3a67562a4f
---
plugins/imtcp/imtcp.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/plugins/imtcp/imtcp.c b/plugins/imtcp/imtcp.c
index 98a060e4c9..0e689a28d8 100644
--- a/plugins/imtcp/imtcp.c
+++ b/plugins/imtcp/imtcp.c
@@ -350,7 +350,7 @@ createInstance(instanceConf_t **pinst)
instanceConf_t *inst = NULL;
DEFiRet;
- CHKmalloc(inst = malloc(sizeof(instanceConf_t)));
+ CHKmalloc(inst = (instanceConf_t*) calloc(1, sizeof(instanceConf_t)));
CHKmalloc(inst->cnf_params = (tcpLstnParams_t*) calloc(1, sizeof(tcpLstnParams_t)));
inst->next = NULL;
inst->pszBindRuleset = NULL;
@@ -400,6 +400,7 @@ createInstance(instanceConf_t **pinst)
*pinst = inst;
finalize_it:
if(iRet != RS_RET_OK) {
+ free(inst->cnf_params);
free(inst);
}
RETiRet;
@@ -431,7 +432,7 @@ static rsRetVal addInstance(void __attribute__((unused)) *pVal, uchar *pNewVal)
CHKmalloc(inst->cnf_params->pszAddr = ustrdup(cs.lstnIP));
}
if((cs.lstnPortFile == NULL) || (cs.lstnPortFile[0] == '\0')) {
- inst->cnf_params->pszAddr = NULL;
+ inst->cnf_params->pszLstnPortFileName = NULL;
} else {
CHKmalloc(inst->cnf_params->pszLstnPortFileName = ustrdup(cs.lstnPortFile));
}
@@ -706,7 +707,6 @@ CODESTARTbeginCnfLoad
loadModConf->bPreserveCase = 1; /* default to true */
bLegacyCnfModGlobalsPermitted = 1;
/* init legacy config variables */
- cs.pszStrmDrvrAuthMode = NULL;
resetConfigVariables(NULL, NULL); /* dummy parameters just to fulfill interface def */
ENDbeginCnfLoad
@@ -906,9 +906,9 @@ ENDactivateCnf
BEGINfreeCnf
instanceConf_t *inst, *del;
CODESTARTfreeCnf
+ free(pModConf->gnutlsPriorityString);
free(pModConf->pszStrmDrvrName);
free(pModConf->pszStrmDrvrAuthMode);
- free(pModConf->gnutlsPriorityString);
free(pModConf->pszStrmDrvrPermitExpiredCerts);
free(pModConf->pszStrmDrvrCAFile);
free(pModConf->pszStrmDrvrKeyFile);
@@ -1024,12 +1024,14 @@ ENDwillRun
BEGINafterRun
CODESTARTafterRun
tcpsrv_etry_t *etry = tcpsrv_root;
+ tcpsrv_etry_t *del;
while(etry != NULL) {
iRet = tcpsrv.Destruct(&etry->tcpsrv);
// TODO: check iRet, reprot error
+ del = etry;
etry = etry->next;
+ free(del);
}
-
net.clearAllowedSenders(UCHAR_CONSTANT("TCP"));
ENDafterRun
@@ -1068,11 +1070,11 @@ resetConfigVariables(uchar __attribute__((unused)) *pp, void __attribute__((unus
cs.iAddtlFrameDelim = TCPSRV_NO_ADDTL_DELIMITER;
cs.maxFrameSize = 200000;
cs.bDisableLFDelim = 0;
- free(cs.pszInputName);
- cs.pszInputName = NULL;
+ cs.bPreserveCase = 1;
free(cs.pszStrmDrvrAuthMode);
cs.pszStrmDrvrAuthMode = NULL;
- cs.bPreserveCase = 1;
+ free(cs.pszInputName);
+ cs.pszInputName = NULL;
free(cs.lstnPortFile);
cs.lstnPortFile = NULL;
return RS_RET_OK;