]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
profiling: fix memory error in case of rule reload.
authorVictor Julien <victor@inliniac.net>
Sun, 16 Sep 2012 10:57:53 +0000 (12:57 +0200)
committerVictor Julien <victor@inliniac.net>
Sun, 16 Sep 2012 10:57:53 +0000 (12:57 +0200)
src/util-profiling-locks.c
src/util-profiling-rules.c
src/util-profiling.c

index 8d31410d6266edbc8b8ae20a6a084d671ec13089..b88e27dd266179c540b47263a333e3aa53ccf23b 100644 (file)
@@ -38,7 +38,7 @@ __thread int record_locks = 0;
 int profiling_locks_enabled = 0;
 int profiling_locks_output_to_file = 0;
 char *profiling_locks_file_name = NULL;
-char *profiling_locks_file_mode = NULL;
+char *profiling_locks_file_mode = "a";
 
 typedef struct LockRecord_ {
     char *file; // hash
@@ -147,11 +147,7 @@ void SCProfilingListLocks(void) {
     FILE *fp = NULL;
 
     if (profiling_locks_output_to_file == 1) {
-        if (strcasecmp(profiling_locks_file_mode, "yes") == 0) {
-            fp = fopen(profiling_locks_file_name, "a");
-        } else {
-            fp = fopen(profiling_locks_file_name, "w");
-        }
+        fp = fopen(profiling_locks_file_name, profiling_locks_file_mode);
 
         if (fp == NULL) {
             SCLogError(SC_ERR_FOPEN, "failed to open %s: %s",
index 20cd4a6a42be42d167ccc84dfd488fa3dbdaaa33..7afa52e1fd9668860df78c4bfa9b7a6726899765 100644 (file)
@@ -87,7 +87,7 @@ static SCProfileData rules_profile_data[0xffff];
 static pthread_mutex_t rules_profile_data_m;
 int profiling_rules_enabled = 0;
 static char *profiling_file_name = "";
-static const char *profiling_file_mode = "";
+static const char *profiling_file_mode = "a";
 
 /**
  * Sort orders for dumping profiled rules.
@@ -173,9 +173,12 @@ void SCProfilingRulesGlobalInit(void) {
                 profiling_file_name = SCMalloc(PATH_MAX);
                 snprintf(profiling_file_name, PATH_MAX, "%s/%s", log_dir, filename);
 
-                profiling_file_mode = ConfNodeLookupChildValue(conf, "append");
-                if (profiling_file_mode == NULL)
-                    profiling_file_mode = DEFAULT_LOG_MODE_APPEND;
+                const char *v = ConfNodeLookupChildValue(conf, "append");
+                if (v == NULL || ConfValIsTrue(v)) {
+                    profiling_file_mode = "a";
+                } else {
+                    profiling_file_mode = "w";
+                }
 
                 profiling_output_to_file = 1;
             }
@@ -272,11 +275,7 @@ SCProfilingRuleDump(SCProfileDetectCtx *rules_ctx)
     struct timeval tval;
     struct tm *tms;
     if (profiling_output_to_file == 1) {
-        if (ConfValIsTrue(profiling_file_mode)) {
-            fp = fopen(profiling_file_name, "a");
-        } else {
-            fp = fopen(profiling_file_name, "w");
-        }
+        fp = fopen(profiling_file_name, profiling_file_mode);
 
         if (fp == NULL) {
             SCLogError(SC_ERR_FOPEN, "failed to open %s: %s", profiling_file_name,
index 92ef3f2387279225c77d7cf29789b78078fb3b0f..135671d6fe2bb3a78cb2ce09380c6ba07eabc8dd 100644 (file)
@@ -94,7 +94,7 @@ int profiling_packets_output_to_file = 0;
 char *profiling_file_name;
 char *profiling_packets_file_name;
 char *profiling_csv_file_name;
-const char *profiling_packets_file_mode;
+const char *profiling_packets_file_mode = "a";
 
 /**
  * Used as a check so we don't double enter a profiling run.
@@ -143,9 +143,12 @@ SCProfilingInit(void)
                 profiling_packets_file_name = SCMalloc(PATH_MAX);
                 snprintf(profiling_packets_file_name, PATH_MAX, "%s/%s", log_dir, filename);
 
-                profiling_packets_file_mode = ConfNodeLookupChildValue(conf, "append");
-                if (profiling_packets_file_mode == NULL)
-                    profiling_packets_file_mode = DEFAULT_LOG_MODE_APPEND;
+                const char *v = ConfNodeLookupChildValue(conf, "append");
+                if (v == NULL || ConfValIsTrue(v)) {
+                    profiling_packets_file_mode = "a";
+                } else {
+                    profiling_packets_file_mode = "w";
+                }
 
                 profiling_packets_output_to_file = 1;
             }
@@ -214,9 +217,12 @@ SCProfilingInit(void)
                 profiling_locks_file_name = SCMalloc(PATH_MAX);
                 snprintf(profiling_locks_file_name, PATH_MAX, "%s/%s", log_dir, filename);
 
-                profiling_locks_file_mode = (char *)ConfNodeLookupChildValue(conf, "append");
-                if (profiling_locks_file_mode == NULL)
-                    profiling_locks_file_mode = DEFAULT_LOG_MODE_APPEND;
+                const char *v = ConfNodeLookupChildValue(conf, "append");
+                if (v == NULL || ConfValIsTrue(v)) {
+                    profiling_locks_file_mode = "a";
+                } else {
+                    profiling_locks_file_mode = "w";
+                }
 
                 profiling_locks_output_to_file = 1;
             }
@@ -267,11 +273,7 @@ void SCProfilingDumpPacketStats(void) {
         return;
 
     if (profiling_packets_output_to_file == 1) {
-        if (strcasecmp(profiling_packets_file_mode, "yes") == 0) {
-            fp = fopen(profiling_packets_file_name, "a");
-        } else {
-            fp = fopen(profiling_packets_file_name, "w");
-        }
+        fp = fopen(profiling_packets_file_name, profiling_packets_file_mode);
 
         if (fp == NULL) {
             SCLogError(SC_ERR_FOPEN, "failed to open %s: %s",