]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
reference: update pcre globals use
authorVictor Julien <victor@inliniac.net>
Wed, 13 May 2015 07:53:49 +0000 (09:53 +0200)
committerVictor Julien <victor@inliniac.net>
Wed, 13 May 2015 07:53:49 +0000 (09:53 +0200)
Don't update globals each time we parse, but instead do it once at
startup.

src/suricata.c
src/util-reference-config.c
src/util-reference-config.h

index 9582b106fb209a8846c30349aa904928dfea089c..d0971ab4843f4bb2a1f9000d78c929f82ea4e7fd 100644 (file)
@@ -2258,6 +2258,7 @@ int main(int argc, char **argv)
     DetectEngineCtx *de_ctx = NULL;
     if (!suri.disabled_detect) {
         SCClassConfInit();
+        SCReferenceConfInit();
         SetupDelayedDetect(&suri);
         if (!suri.delayed_detect) {
             de_ctx = DetectEngineCtxInit();
@@ -2487,6 +2488,7 @@ int main(int argc, char **argv)
         DefragDestroy();
     }
     if (!suri.disabled_detect) {
+        SCReferenceConfDeinit();
         SCClassConfDeinit();
     }
     MagicDeinit();
index 59aaf0a9fcbf01c473368675ce475317102e1078..a2f09bd360424bee6ad4462901e0afd7b6ed66ae 100644 (file)
@@ -41,8 +41,6 @@
 /* Default path for the reference.conf file */
 #define SC_RCONF_DEFAULT_FILE_PATH CONFIG_DIR "/reference.config"
 
-/* Holds a pointer to the default path for the reference.config file */
-static const char *file_path = SC_RCONF_DEFAULT_FILE_PATH;
 static pcre *regex = NULL;
 static pcre_extra *regex_study = NULL;
 
@@ -55,6 +53,43 @@ void SCRConfReferenceHashFree(void *ch);
 /* used to get the reference.config file path */
 static char *SCRConfGetConfFilename(void);
 
+void SCReferenceConfInit(void)
+{
+    const char *eb = NULL;
+    int eo;
+    int opts = 0;
+
+    regex = pcre_compile(SC_RCONF_REGEX, opts, &eb, &eo, NULL);
+    if (regex == NULL) {
+        SCLogDebug("Compile of \"%s\" failed at offset %" PRId32 ": %s",
+                   SC_RCONF_REGEX, eo, eb);
+        return;
+    }
+
+    regex_study = pcre_study(regex, 0, &eb);
+    if (eb != NULL) {
+        pcre_free(regex);
+        regex = NULL;
+        SCLogDebug("pcre study failed: %s", eb);
+        return;
+    }
+
+    return;
+}
+
+void SCReferenceConfDeinit(void)
+{
+    if (regex != NULL) {
+        pcre_free(regex);
+        regex = NULL;
+    }
+    if (regex_study != NULL) {
+        pcre_free(regex_study);
+        regex_study = NULL;
+    }
+}
+
+
 /**
  * \brief Inits the context to be used by the Reference Config parsing API.
  *
@@ -71,9 +106,6 @@ static char *SCRConfGetConfFilename(void);
 static FILE *SCRConfInitContextAndLocalResources(DetectEngineCtx *de_ctx, FILE *fd)
 {
     char *filename = NULL;
-    const char *eb = NULL;
-    int eo;
-    int opts = 0;
 
     /* init the hash table to be used by the reference config references */
     de_ctx->reference_conf_ht = HashTableInit(128, SCRConfReferenceHashFunc,
@@ -102,19 +134,6 @@ static FILE *SCRConfInitContextAndLocalResources(DetectEngineCtx *de_ctx, FILE *
         }
     }
 
-    regex = pcre_compile(SC_RCONF_REGEX, opts, &eb, &eo, NULL);
-    if (regex == NULL) {
-        SCLogDebug("Compile of \"%s\" failed at offset %" PRId32 ": %s",
-                   SC_RCONF_REGEX, eo, eb);
-        goto error;
-    }
-
-    regex_study = pcre_study(regex, 0, &eb);
-    if (eb != NULL) {
-        SCLogDebug("pcre study failed: %s", eb);
-        goto error;
-    }
-
     return fd;
 
  error:
@@ -127,15 +146,6 @@ static FILE *SCRConfInitContextAndLocalResources(DetectEngineCtx *de_ctx, FILE *
         fd = NULL;
     }
 
-    if (regex != NULL) {
-        pcre_free(regex);
-        regex = NULL;
-    }
-    if (regex_study != NULL) {
-        pcre_free(regex_study);
-        regex_study = NULL;
-    }
-
     return NULL;
 }
 
@@ -153,7 +163,7 @@ static char *SCRConfGetConfFilename(void)
 {
     char *path = NULL;
     if (ConfGet("reference-config-file", &path) != 1) {
-        return (char *)file_path;
+        return (char *)SC_RCONF_DEFAULT_FILE_PATH;
     }
     return path;
 }
@@ -167,16 +177,6 @@ static void SCRConfDeInitLocalResources(DetectEngineCtx *de_ctx, FILE *fd)
         fclose(fd);
         fd = NULL;
     }
-    file_path = SC_RCONF_DEFAULT_FILE_PATH;
-
-    if (regex != NULL) {
-        pcre_free(regex);
-        regex = NULL;
-    }
-    if (regex_study != NULL) {
-        pcre_free(regex_study);
-        regex_study = NULL;
-    }
 
     return;
 }
index 98cc51b149752de86a0b8cb386d1631ae7ca1fe2..f7fe4cc1ebdbb8a47751c3c3b4fa30688548c0e5 100644 (file)
@@ -47,4 +47,7 @@ FILE *SCRConfGenerateValidDummyReferenceConfigFD01(void);
 FILE *SCRConfGenerateInValidDummyReferenceConfigFD02(void);
 FILE *SCRConfGenerateInValidDummyReferenceConfigFD03(void);
 
+void SCReferenceConfInit(void);
+void SCReferenceConfDeinit(void);
+
 #endif /* __UTIL_REFERENCE_CONFIG_H__ */