From: Victor Julien Date: Thu, 30 Jan 2014 15:02:17 +0000 (+0100) Subject: Fix util-debug scan-build warnings X-Git-Tag: suricata-2.0rc1~58 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9ef9a14315127a0464002ea36d8c9a2095bf6dc3;p=thirdparty%2Fsuricata.git Fix util-debug scan-build warnings util-debug.c:461:12: warning: Potential leak of memory pointed to by 'substr' return SC_ERR_SPRINTF; ^~~~~~~~~~~~~~ util-debug.c:856:31: warning: Potential leak of memory pointed to by 's' op_ifaces_ctx = SCLogInitFileOPIface(s, NULL, SC_LOG_LEVEL_MAX); ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ util-debug.c:1349:9: warning: Potential leak of memory pointed to by 's' if (log_level >= 0 && log_level < SC_LOG_LEVEL_MAX) ^~~~~~~~~ 3 warnings generated. --- diff --git a/src/util-debug.c b/src/util-debug.c index c093ab0382..8283c99c5f 100644 --- a/src/util-debug.c +++ b/src/util-debug.c @@ -456,7 +456,7 @@ SCError SCLogMessage(SCLogLevel log_level, char **msg, const char *file, return SC_OK; error: - if (temp_fmt != NULL) + if (temp_fmt_h != NULL) SCFree(temp_fmt_h); return SC_ERR_SPRINTF; } @@ -850,10 +850,15 @@ static inline void SCLogSetOPIface(SCLogInitData *sc_lid, SCLogConfig *sc_lc) break; case SC_LOG_OP_IFACE_FILE: s = getenv(SC_LOG_ENV_LOG_FILE); - if (s == NULL) - s = SCLogGetLogFilename(SC_LOG_DEF_LOG_FILE); - - op_ifaces_ctx = SCLogInitFileOPIface(s, NULL, SC_LOG_LEVEL_MAX); + if (s == NULL) { + char *str = SCLogGetLogFilename(SC_LOG_DEF_LOG_FILE); + if (str != NULL) { + op_ifaces_ctx = SCLogInitFileOPIface(str, NULL, SC_LOG_LEVEL_MAX); + SCFree(str); + } + } else { + op_ifaces_ctx = SCLogInitFileOPIface(s, NULL, SC_LOG_LEVEL_MAX); + } break; case SC_LOG_OP_IFACE_SYSLOG: s = getenv(SC_LOG_ENV_LOG_FACILITY); @@ -1290,9 +1295,15 @@ void SCLogInitLogModuleIfEnvSet(void) break; case SC_LOG_OP_IFACE_FILE: s = getenv(SC_LOG_ENV_LOG_FILE); - if (s == NULL) - s = SCLogGetLogFilename(SC_LOG_DEF_LOG_FILE); - op_ifaces_ctx = SCLogInitFileOPIface(s, NULL, -1); + if (s == NULL) { + char *str = SCLogGetLogFilename(SC_LOG_DEF_LOG_FILE); + if (str != NULL) { + op_ifaces_ctx = SCLogInitFileOPIface(str, NULL, SC_LOG_LEVEL_MAX); + SCFree(str); + } + } else { + op_ifaces_ctx = SCLogInitFileOPIface(s, NULL, -1); + } break; case SC_LOG_OP_IFACE_SYSLOG: s = getenv(SC_LOG_ENV_LOG_FACILITY);