From 9ef9a14315127a0464002ea36d8c9a2095bf6dc3 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Thu, 30 Jan 2014 16:02:17 +0100 Subject: [PATCH] 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. --- src/util-debug.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) 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);