bugfix: check array bounds
bugfix: check return value of calloc()
bugfix: check return value of malloc()
bugfix: prevent a double free

cstrConvSzStrAndDestruct() frees it's first argument but doesn't set
it to NULL as rsCStrDestruct() does. In couple of cases the code using
it assumed it does which could have led to double free.
This commit aligns the prototype of cstrConvSzStrAndDestruct() with
rsCStrDestruct(). The callers were updated for the new behavior and
several potential memleaks were plugged.

Error: USE_AFTER_FREE (CWE-825):
rsyslog-7.4.10/runtime/cfsysline.c:532: freed_arg: "cstrConvSzStrAndDestruct(cstr_t *, uchar **, int)" frees "pStrB".
rsyslog-7.4.10/runtime/stringbuf.c:486:2: freed_arg: "free(void *)" frees parameter "pThis".
rsyslog-7.4.10/runtime/cfsysline.c:553: deref_arg: Calling "rsCStrDestruct(cstr_t **)" dereferences freed pointer "pStrB".
rsyslog-7.4.10/runtime/stringbuf.c:216:16: var_assign_parm: Assigning: "pThis" = "*ppThis".
rsyslog-7.4.10/runtime/stringbuf.c:218:2: deref_var: Dereferencing "pThis" (which is a copy of "*ppThis").

Error: USE_AFTER_FREE (CWE-825):
rsyslog-7.4.10/outchannel.c:113: freed_arg: "cstrConvSzStrAndDestruct(cstr_t *, uchar **, int)" frees "pStrB".
rsyslog-7.4.10/runtime/stringbuf.c:486:2: freed_arg: "free(void *)" frees parameter "pThis".
rsyslog-7.4.10/outchannel.c:118: deref_arg: Calling "rsCStrDestruct(cstr_t **)" dereferences freed pointer "pStrB".
rsyslog-7.4.10/runtime/stringbuf.c:216:16: var_assign_parm: Assigning: "pThis" = "*ppThis".
rsyslog-7.4.10/runtime/stringbuf.c:218:2: deref_var: Dereferencing "pThis" (which is a copy of "*ppThis").

Error: USE_AFTER_FREE (CWE-825):
rsyslog-7.4.10/outchannel.c:181: freed_arg: "cstrConvSzStrAndDestruct(cstr_t *, uchar **, int)" frees "pStrB".
rsyslog-7.4.10/runtime/stringbuf.c:486:2: freed_arg: "free(void *)" frees parameter "pThis".
rsyslog-7.4.10/outchannel.c:186: deref_arg: Calling "rsCStrDestruct(cstr_t **)" dereferences freed pointer "pStrB".
rsyslog-7.4.10/runtime/stringbuf.c:216:16: var_assign_parm: Assigning: "pThis" = "*ppThis".
rsyslog-7.4.10/runtime/stringbuf.c:218:2: deref_var: Dereferencing "pThis" (which is a copy of "*ppThis").

Error: USE_AFTER_FREE (CWE-825):
rsyslog-7.4.10/template.c:480: freed_arg: "cstrConvSzStrAndDestruct(cstr_t *, uchar **, int)" frees "pStrB".
rsyslog-7.4.10/runtime/stringbuf.c:486:2: freed_arg: "free(void *)" frees parameter "pThis".
rsyslog-7.4.10/template.c:493: deref_arg: Calling "rsCStrDestruct(cstr_t **)" dereferences freed pointer "pStrB".
rsyslog-7.4.10/runtime/stringbuf.c:216:16: var_assign_parm: Assigning: "pThis" = "*ppThis".
rsyslog-7.4.10/runtime/stringbuf.c:218:2: deref_var: Dereferencing "pThis" (which is a copy of "*ppThis").
bugfix: check return value of calloc()
bugfix: check return value of ratelimitNew()
bugfix: plug a memleak
bugfix: remove redundant return
bugfix: add a missing pointer assignment
bugfix: propagate an error code

Previously, the return value was lost as iRet is overwritten in
CHKiRet(). The error code is not handled currently thus the utility is
disputable.
bugfix: plug memleaks in imptcp

Error: RESOURCE_LEAK (CWE-772):
rsyslog-7.4.10/plugins/imptcp/imptcp.c:925: alloc_fn: Storage is returned from allocation function "malloc(size_t)".
rsyslog-7.4.10/plugins/imptcp/imptcp.c:925: var_assign: Assigning: "pLstn" = storage returned from "malloc(56UL)".
rsyslog-7.4.10/plugins/imptcp/imptcp.c:951: leaked_storage: Variable "pLstn" going out of scope leaks the storage it points to.
bugfix: don't add listener to the server upon failure

The listener should be added after everything else is completed.
bugfix: plug more memleaks in imptcp

Error: RESOURCE_LEAK (CWE-772):
rsyslog-7.4.10/plugins/imptcp/imptcp.c:964: alloc_fn: Storage is returned from allocation function "malloc(size_t)".
rsyslog-7.4.10/plugins/imptcp/imptcp.c:964: var_assign: Assigning: "pSess" = storage returned from "malloc(88UL)".
rsyslog-7.4.10/plugins/imptcp/imptcp.c:987: leaked_storage: Variable "pSess" going out of scope leaks the storage it points to.
bugfix: don't add session to the server upon failure

The session should be added after everything else is completed.
bugfix: plug more memleaks in imptcp
bugfix: plug more memleaks in imptcp

Error: RESOURCE_LEAK (CWE-772):
rsyslog-7.4.10/plugins/imptcp/imptcp.c:1120: alloc_fn: Storage is returned from allocation function "malloc(size_t)".
rsyslog-7.4.10/plugins/imptcp/imptcp.c:1120: var_assign: Assigning: "pSrv" = storage returned from "malloc(136UL)".
rsyslog-7.4.10/plugins/imptcp/imptcp.c:1159: leaked_storage: Variable "pSrv" going out of scope leaks the storage it points to.
bugfix: prevent leaking a socket in case of an error

Error: RESOURCE_LEAK (CWE-772):
rsyslog-7.4.10/plugins/imptcp/imptcp.c:1252: open_arg: "AcceptConnReq(ptcplstn_t *, int *, prop_t **, prop_t **)" opens handle stored into "newSock".
rsyslog-7.4.10/plugins/imptcp/imptcp.c:615:2: open_fn: Returning handle opened by function "accept(int, __SOCKADDR_ARG, socklen_t * restrict)".
rsyslog-7.4.10/plugins/imptcp/imptcp.c:615:2: var_assign: Assigning: "iNewSock" = "accept(pLstn->sock, __SOCKADDR_ARG({ .__sockaddr__ = (struct sockaddr *)&addr}), &addrlen)".
rsyslog-7.4.10/plugins/imptcp/imptcp.c:623:3: noescape: Resource "iNewSock" is not freed or pointed-to in function "EnableKeepAlive(ptcplstn_t *, int)".
rsyslog-7.4.10/plugins/imptcp/imptcp.c:535:40: noescape: "EnableKeepAlive(ptcplstn_t *, int)" does not free or save its handle parameter "sock".
rsyslog-7.4.10/plugins/imptcp/imptcp.c:629:2: noescape: Resource "iNewSock" is not freed or pointed-to in function "fcntl(int, int, ...)".
rsyslog-7.4.10/plugins/imptcp/imptcp.c:634:3: noescape: Resource "iNewSock" is not freed or pointed-to in function "fcntl(int, int, ...)".
rsyslog-7.4.10/plugins/imptcp/imptcp.c:641:2: var_assign: Assigning: "*newSock" = "iNewSock".
rsyslog-7.4.10/plugins/imptcp/imptcp.c:1260: leaked_handle: Handle variable "newSock" going out of scope leaks the handle.
bugfix: add a missing cleanup in case of an error

Error: RESOURCE_LEAK (CWE-772):
rsyslog-7.4.10/plugins/imudp/imudp.c:260: alloc_fn: Storage is returned from allocation function "malloc(size_t)".
rsyslog-7.4.10/plugins/imudp/imudp.c:260: var_assign: Assigning: "newlcnfinfo" = storage returned from "malloc(56UL)".
rsyslog-7.4.10/plugins/imudp/imudp.c:307: leaked_storage: Variable "newlcnfinfo" going out of scope leaks the storage it points to.
bugfix: plug a memleak in imudp

Error: RESOURCE_LEAK (CWE-772):
rsyslog-7.4.10/plugins/imudp/imudp.c:413: alloc_arg: "msgConstructWithTime(msg_t **, struct syslogTime *, time_t)" allocates memory that is stored into "pMsg".
rsyslog-7.4.10/runtime/msg.c:745:2: alloc_arg: "msgBaseConstruct(msg_t **)" allocates memory that is stored into "*ppThis".
rsyslog-7.4.10/runtime/msg.c:674:2: alloc_fn: Storage is returned from allocation function "malloc(size_t)".
rsyslog-7.4.10/runtime/msg.c:674:2: var_assign: Assigning: "pM" = "malloc(576UL)".
rsyslog-7.4.10/runtime/msg.c:725:2: var_assign: Assigning: "*ppThis" = "pM".
rsyslog-7.4.10/plugins/imudp/imudp.c:414: noescape: Resource "pMsg" is not freed or pointed-to in function "MsgSetRawMsg(msg_t *, char *, size_t)".
rsyslog-7.4.10/runtime/msg.c:2403:26: noescape: "MsgSetRawMsg(msg_t *, char *, size_t)" does not free or save its pointer parameter "pThis".
rsyslog-7.4.10/plugins/imudp/imudp.c:415: noescape: Resource "pMsg" is not freed or pointed-to in function "MsgSetInputName(msg_t *, prop_t *)".
rsyslog-7.4.10/runtime/msg.c:2208:29: noescape: "MsgSetInputName(msg_t *, prop_t *)" does not free or save its pointer parameter "pThis".
rsyslog-7.4.10/plugins/imudp/imudp.c:416: noescape: Resource "pMsg" is not freed or pointed-to in function "MsgSetRuleset(msg_t *, ruleset_t *)".
rsyslog-7.4.10/runtime/msg.c:1921:27: noescape: "MsgSetRuleset(msg_t *, ruleset_t *)" does not free or save its pointer parameter "pMsg".
rsyslog-7.4.10/plugins/imudp/imudp.c:417: noescape: Resource "pMsg" is not freed or pointed-to in function "MsgSetFlowControlType(msg_t *, flowControl_t)".
rsyslog-7.4.10/runtime/msg.c:1755:30: noescape: "MsgSetFlowControlType(msg_t *, flowControl_t)" does not free or save its pointer parameter "pMsg".
rsyslog-7.4.10/plugins/imudp/imudp.c:421: noescape: Resource "pMsg" is not freed or pointed-to in function "msgSetFromSockinfo(msg_t *, struct sockaddr_storage *)".
rsyslog-7.4.10/runtime/msg.c:2229:27: noescape: "msgSetFromSockinfo(msg_t *, struct sockaddr_storage *)" does not free or save its pointer parameter "pThis".
rsyslog-7.4.10/plugins/imudp/imudp.c:436: leaked_storage: Variable "pMsg" going out of scope leaks the storage it points to.
cosmetic: fix some gcc --pedantic messages