diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2007-09-04 13:20:07 +0000 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2007-09-04 13:20:07 +0000 |
commit | 79a68894b4f63d1684996718f7411e4163d76bba (patch) | |
tree | 4a945db849dd3aae7215d9ef084da53d91c0dfe0 /template.c | |
parent | 5b17b10f432c9b7280624b14ae2f656a34a1a829 (diff) | |
download | rsyslog-79a68894b4f63d1684996718f7411e4163d76bba.tar.gz rsyslog-79a68894b4f63d1684996718f7411e4163d76bba.tar.bz2 rsyslog-79a68894b4f63d1684996718f7411e4163d76bba.zip |
applied patch form varmojfekoj to fix some mem leaks and a check to make
sure that an empty string (NULL) returned by the CStr class does not
cause a program abort.
Diffstat (limited to 'template.c')
-rw-r--r-- | template.c | 17 |
1 files changed, 13 insertions, 4 deletions
@@ -108,7 +108,11 @@ uchar *tplToString(struct template *pTpl, msg_t *pMsg) * "real" (usable) string and discard the helper structures. */ rsCStrFinish(pCStr); - return rsCStrConvSzStrAndDestruct(pCStr); + if((pVal = rsCStrConvSzStrAndDestruct(pCStr)) == NULL) { + pVal = malloc(1); + *pVal = '\0'; + } + return pVal; } /* Helper to doSQLEscape. This is called if doSQLEscape @@ -293,7 +297,7 @@ struct template* tplConstruct(void) */ static int do_Constant(unsigned char **pp, struct template *pTpl) { - register unsigned char *p; + register unsigned char *p, *s; rsCStrObj *pStrB; struct templateEntry *pTpe; int i; @@ -373,8 +377,13 @@ static int do_Constant(unsigned char **pp, struct template *pTpl) * benefit from the counted string object. * 2005-09-09 rgerhards */ - pTpe->data.constant.iLenConstant = rsCStrLen(pStrB); - pTpe->data.constant.pConstant = (char*) rsCStrConvSzStrAndDestruct(pStrB); + if ((pTpe->data.constant.iLenConstant = rsCStrLen(pStrB)) == 0) { + s = malloc(1); + *s = '\0'; + rsCStrDestruct(pStrB); + } else + s = rsCStrConvSzStrAndDestruct(pStrB); + pTpe->data.constant.pConstant = (char*) s; *pp = p; |