bugfix: plug a memleak in imuxsock

Error: RESOURCE_LEAK (CWE-772):
rsyslog-7.4.10/plugins/imuxsock/imuxsock.c:584: alloc_arg: "ratelimitNew(ratelimit_t **, char *, char *)" allocates memory that is stored into "rl".
rsyslog-7.4.10/runtime/ratelimit.c:290:2: alloc_fn: Storage is returned from allocation function "calloc(size_t, size_t)".
rsyslog-7.4.10/runtime/ratelimit.c:290:2: var_assign: Assigning: "pThis" = "calloc(1UL, 96UL)".
rsyslog-7.4.10/runtime/ratelimit.c:304:2: var_assign: Assigning: "*ppThis" = "pThis".
rsyslog-7.4.10/plugins/imuxsock/imuxsock.c:585: noescape: Resource "rl" is not freed or pointed-to in function "ratelimitSetLinuxLike(ratelimit_t *, unsigned short, unsigned short)".
rsyslog-7.4.10/runtime/ratelimit.c:312:36: noescape: "ratelimitSetLinuxLike(ratelimit_t *, unsigned short, unsigned short)" does not free or save its pointer parameter "ratelimit".
rsyslog-7.4.10/plugins/imuxsock/imuxsock.c:586: noescape: Resource "rl" is not freed or pointed-to in function "ratelimitSetSeverity(ratelimit_t *, intTiny)".
rsyslog-7.4.10/runtime/ratelimit.c:345:35: noescape: "ratelimitSetSeverity(ratelimit_t *, intTiny)" does not free or save its pointer parameter "ratelimit".
rsyslog-7.4.10/plugins/imuxsock/imuxsock.c:599: leaked_storage: Variable "rl" going out of scope leaks the storage it points to.
bugfix: plug memleaks and refactor the SubmitMsg function

Error: RESOURCE_LEAK (CWE-772):
rsyslog-7.4.10/plugins/imuxsock/imuxsock.c:797: alloc_fn: Storage is returned from allocation function "malloc(size_t)".
rsyslog-7.4.10/plugins/imuxsock/imuxsock.c:797: var_assign: Assigning: "pmsgbuf" = storage returned from "malloc(lenRcv + 4096)".
rsyslog-7.4.10/plugins/imuxsock/imuxsock.c:822: noescape: Resource "pmsgbuf" is not freed or pointed-to in function "memcpy(void * restrict, void const * restrict, size_t)".
rsyslog-7.4.10/plugins/imuxsock/imuxsock.c:823: noescape: Resource "pmsgbuf + lenRcv" is not freed or pointed-to in function "memcpy(void * restrict, void const * restrict, size_t)".
rsyslog-7.4.10/plugins/imuxsock/imuxsock.c:828: noescape: Resource "pmsgbuf + toffs" is not freed or pointed-to in function "memcpy(void * restrict, void const * restrict, size_t)".
rsyslog-7.4.10/plugins/imuxsock/imuxsock.c:851: var_assign: Assigning: "pRcv" = "pmsgbuf".
rsyslog-7.4.10/plugins/imuxsock/imuxsock.c:858: noescape: Resource "(char *)pRcv" is not freed or pointed-to in function "MsgSetRawMsg(msg_t *, char *, size_t)".
rsyslog-7.4.10/runtime/msg.c:2403:39: noescape: "MsgSetRawMsg(msg_t *, char *, size_t)" does not free or save its pointer parameter "pszRawMsg".
rsyslog-7.4.10/plugins/imuxsock/imuxsock.c:928: leaked_storage: Variable "pmsgbuf" going out of scope leaks the storage it points to.
rsyslog-7.4.10/plugins/imuxsock/imuxsock.c:928: leaked_storage: Returning without freeing "pRcv" leaks the storage that it points to.

Error: RESOURCE_LEAK (CWE-772):
rsyslog-7.4.10/plugins/imuxsock/imuxsock.c:797: alloc_fn: Storage is returned from allocation function "malloc(size_t)".
rsyslog-7.4.10/plugins/imuxsock/imuxsock.c:797: var_assign: Assigning: "pmsgbuf" = storage returned from "malloc(lenRcv + 4096)".
rsyslog-7.4.10/plugins/imuxsock/imuxsock.c:928: leaked_storage: Variable "pmsgbuf" going out of scope leaks the storage it points to.
bugfix: check return value of malloc()

Error: NULL_RETURNS (CWE-476):
rsyslog-7.4.10/plugins/imuxsock/imuxsock.c:1336: returned_null: Function "malloc(size_t)" returns null (checked 140 out of 168 times).
rsyslog-7.4.10/action.c:1197: example_checked: Example 1: "malloc(batchNumMsgs(pBatch) * 1UL)" has its value checked in "(active = malloc(batchNumMsgs(pBatch) * 1UL)) == NULL".
rsyslog-7.4.10/grammar/lexer.l:302: example_checked: Example 2: "malloc(40UL)" has its value checked in "(bs = malloc(40UL)) == NULL".
rsyslog-7.4.10/grammar/rainerscript.c:2483: example_checked: Example 3: "malloc(8UL)" has its value checked in "(ar->arr = malloc(8UL)) == NULL".
rsyslog-7.4.10/plugins/imklog/bsd.c:221: example_checked: Example 4: "malloc(1UL * (iMaxLine + 1))" has its value checked in "(pRcv = (uchar *)malloc(1UL * (iMaxLine + 1))) == NULL".
rsyslog-7.4.10/plugins/imuxsock/imuxsock.c:968: example_checked: Example 5: "malloc(1UL * (iMaxLine + 1))" has its value checked in "(pRcv = (uchar *)malloc(1UL * (iMaxLine + 1))) == NULL".
rsyslog-7.4.10/plugins/imuxsock/imuxsock.c:1336: var_assigned: Assigning: "pReadfds" = null return value from "malloc(size_t)".
rsyslog-7.4.10/plugins/imuxsock/imuxsock.c:1355: dereference: Dereferencing a pointer that might be null "pReadfds" when calling "memset(void *, int, size_t)".
Remove redundant return
bugfix: correct array boundaries check

Error: OVERRUN (CWE-119):
rsyslog-7.4.10/plugins/mmcount/mmcount.c:264: cond_at_most: Checking "pMsg->iSeverity <= 8" implies that the value of "pMsg->iSeverity" may be up to 8 on the true branch.
rsyslog-7.4.10/plugins/mmcount/mmcount.c:265: overrun-local: Overrunning array "pData->severity" of 8 4-byte elements at element index 8 (byte offset 32) using index "pMsg->iSeverity" (which evaluates to 8).
bugfix: plug a memleak in mmsnmptrapd

Error: RESOURCE_LEAK (CWE-772):
rsyslog-7.4.10/plugins/mmsnmptrapd/mmsnmptrapd.c:292: alloc_fn: Storage is returned from allocation function "malloc(size_t)".
rsyslog-7.4.10/plugins/mmsnmptrapd/mmsnmptrapd.c:292: var_assign: Assigning: "node" = storage returned from "malloc(24UL)".
rsyslog-7.4.10/plugins/mmsnmptrapd/mmsnmptrapd.c:303: leaked_storage: Variable "node" going out of scope leaks the storage it points to.
Don't assign unused value

Error: CLANG_WARNING:
rsyslog-7.4.10/plugins/omelasticsearch/omelasticsearch.c:208:13: warning: Value stored to 'r' is never read
Don't assign unused value

Error: CLANG_WARNING:
rsyslog-7.4.10/plugins/omelasticsearch/omelasticsearch.c:368:14: warning: Value stored to 'r' is never read
Remove dead code

Error: DEADCODE (CWE-561):
rsyslog-7.4.10/plugins/ommail/ommail.c:143: cond_null: Condition "(pNew = calloc(1UL, 16UL)) == NULL", taking true branch. Now the value of "pNew" is NULL.
rsyslog-7.4.10/plugins/ommail/ommail.c:153: null: At condition "pNew != NULL", the value of "pNew" must be NULL.
rsyslog-7.4.10/plugins/ommail/ommail.c:153: dead_error_condition: The condition "pNew != NULL" cannot be true.
rsyslog-7.4.10/plugins/ommail/ommail.c:154: dead_error_line: Execution cannot reach this statement "free(pNew);".
Prevent passing null to putenv()

Replace putenv() with setenv() which handles memory allocation by itself.

Error: CLANG_WARNING:
rsyslog-7.4.10/plugins/omsnmp/omsnmp.c:206:2: warning: Null pointer passed as an argument to a 'nonnull' parameter
bugfix: check return value of malloc()

Error: NULL_RETURNS (CWE-476):
rsyslog-7.4.10/plugins/omsnmp/omsnmp.c:264: returned_null: Function "malloc(size_t)" returns null (checked 140 out of 168 times).
rsyslog-7.4.10/action.c:1197: example_checked: Example 1: "malloc(batchNumMsgs(pBatch) * 1UL)" has its value checked in "(active = malloc(batchNumMsgs(pBatch) * 1UL)) == NULL".
rsyslog-7.4.10/grammar/lexer.l:302: example_checked: Example 2: "malloc(40UL)" has its value checked in "(bs = malloc(40UL)) == NULL".
rsyslog-7.4.10/grammar/rainerscript.c:2483: example_checked: Example 3: "malloc(8UL)" has its value checked in "(ar->arr = malloc(8UL)) == NULL".
rsyslog-7.4.10/plugins/imklog/bsd.c:221: example_checked: Example 4: "malloc(1UL * (iMaxLine + 1))" has its value checked in "(pRcv = (uchar *)malloc(1UL * (iMaxLine + 1))) == NULL".
rsyslog-7.4.10/plugins/imuxsock/imuxsock.c:968: example_checked: Example 5: "malloc(1UL * (iMaxLine + 1))" has its value checked in "(pRcv = (uchar *)malloc(1UL * (iMaxLine + 1))) == NULL".
rsyslog-7.4.10/plugins/omsnmp/omsnmp.c:264: var_assigned: Assigning: "pdu->enterprise" = null return value from "malloc(size_t)".
rsyslog-7.4.10/plugins/omsnmp/omsnmp.c:265: dereference: Dereferencing a pointer that might be null "pdu->enterprise" when calling "memcpy(void * restrict, void const * restrict, size_t)".
Remove unused variable

Error: COMPILER_WARNING:
rsyslog-7.4.10/plugins/pmaixforwardedfrom/pmaixforwardedfrom.c: scope_hint: In function 'parse'
rsyslog-7.4.10/plugins/pmaixforwardedfrom/pmaixforwardedfrom.c:72: warning: unused variable 'opening'
bugfix: don't leak memory when realloc() fails

Error: CPPCHECK_WARNING:
rsyslog-7.4.10/runtime/cfsysline.c:368: error[memleakOnRealloc]: Common realloc mistake: 'stringBuf' nulled but not freed upon failure
bugfix: check return value

Error: CLANG_WARNING:
rsyslog-7.4.10/runtime/cfsysline.c:918:2: warning: Value stored to 'iRet' is never read
Prevent dereferencing a NULL pointer

Error: NULL_RETURNS (CWE-476):
rsyslog-7.4.10/runtime/debug.c:698: returned_null: Function "calloc(size_t, size_t)" returns null (checked 107 out of 123 times).
rsyslog-7.4.10/action.c:333: example_checked: Example 1: "calloc(1UL, 264UL)" has its value checked in "(pThis = (action_t *)calloc(1UL, 264UL)) == NULL".
rsyslog-7.4.10/grammar/rainerscript.c:932: example_checked: Example 2: "calloc(params->nParams, 24UL)" has its value checked in "(vals = calloc(params->nParams, 24UL)) == NULL".
rsyslog-7.4.10/outchannel.c:47: example_checked: Example 3: "calloc(1UL, 48UL)" has its value checked in "(pOch = calloc(1UL, 48UL)) == NULL".
rsyslog-7.4.10/parse.c:75: example_checked: Example 4: "calloc(1UL, 16UL)" has its value checked in "(pThis = (rsParsObj *)calloc(1UL, 16UL)) == NULL".
rsyslog-7.4.10/plugins/imfile/imfile.c:496: example_checked: Example 5: "calloc(1UL, 40UL)" has its value checked in "(pModConf = calloc(1UL, 40UL)) == NULL".
rsyslog-7.4.10/runtime/debug.c:698: var_assigned: Assigning: "pThrd" = null return value from "calloc(size_t, size_t)".
rsyslog-7.4.10/runtime/debug.c:699: dereference: Dereferencing a null pointer "pThrd".
bugfix: prevent a potential memleak

Error: RESOURCE_LEAK (CWE-772):
rsyslog-7.4.10/runtime/modules.c:394: alloc_fn: Storage is returned from allocation function "malloc(size_t)".
rsyslog-7.4.10/runtime/modules.c:394: var_assign: Assigning: "pNew" = storage returned from "malloc(32UL)".
rsyslog-7.4.10/runtime/modules.c:406: leaked_storage: Variable "pNew" going out of scope leaks the storage it points to.
Use uchar instead of char for type size reference

Error: CLANG_WARNING:
rsyslog-7.4.10/runtime/modules.c:1086:26: warning: Result of 'malloc' is converted to a pointer of type 'uchar', which is incompatible with sizeof operand type 'char'
rsyslog-7.4.10/runtime/rsyslog.h:441:34: note: expanded from macro 'CHKmalloc'

Error: CLANG_WARNING:
rsyslog-7.4.10/runtime/modules.c:1109:26: warning: Result of 'malloc' is converted to a pointer of type 'uchar', which is incompatible with sizeof operand type 'char'
rsyslog-7.4.10/runtime/rsyslog.h:441:34: note: expanded from macro 'CHKmalloc'
Remove dead code

Error: CLANG_WARNING:
rsyslog-7.4.10/runtime/modules.c:1133:4: warning: Value stored to 'iPathLen' is never read
bugfix: escape '/' in JSON strings

Error: DEADCODE (CWE-561):
rsyslog-7.4.10/runtime/msg.c:2602: cond_at_most: Condition "c >= 35", taking false branch. Now the value of "c" is at most 34.
rsyslog-7.4.10/runtime/msg.c:2602: cond_at_most: Condition "c >= 93", taking false branch. Now the value of "c" is at most 34.
rsyslog-7.4.10/runtime/msg.c:2602: cond_at_least: Condition "c >= 35", taking true branch. Now the value of "c" is at least 35.
rsyslog-7.4.10/runtime/msg.c:2602: cond_at_least: Condition "c <= 91", taking false branch. Now the value of "c" is at least 92.
rsyslog-7.4.10/runtime/msg.c:2602: cond_const: Condition "c >= 93", taking false branch. Now the value of "c" is equal to 92.
rsyslog-7.4.10/runtime/msg.c:2621: intervals: When switching on "c", the value of "c" must be in one of the following intervals: {(-inf,34], [92,92]}.
rsyslog-7.4.10/runtime/msg.c:2628: dead_error_condition: The switch value "c" cannot be "47".
rsyslog-7.4.10/runtime/msg.c:2628: dead_error_begin: Execution cannot reach this statement "case 47:".
Remove dead code