]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Fix util-debug scan-build warnings
authorVictor Julien <victor@inliniac.net>
Thu, 30 Jan 2014 15:02:17 +0000 (16:02 +0100)
committerVictor Julien <victor@inliniac.net>
Fri, 31 Jan 2014 12:30:11 +0000 (13:30 +0100)
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

index c093ab0382839d82e20e01c675ec257cb9aedb96..8283c99c5f37ca720667ac3dfe06a0385fbb4630 100644 (file)
@@ -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);