]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
affinity: avoid to init structure twice
authorEric Leblond <eric@regit.org>
Fri, 26 Oct 2012 08:31:13 +0000 (10:31 +0200)
committerEric Leblond <eric@regit.org>
Mon, 19 Nov 2012 22:54:26 +0000 (23:54 +0100)
In unix socket mode, suricata was doing multiple init of the
structure. This was not needed and caused a memory leak in
mutex creation.

src/util-affinity.c

index d61b70d0e28a6c08d975a13a2ea558e1ebb35e67..875da6ff89fb2353d10d782a3d8a3777be60618f 100644 (file)
@@ -83,6 +83,8 @@ ThreadsAffinityType thread_affinity[MAX_CPU_SET] = {
 
 };
 
+int thread_affinity_init_done = 0;
+
 /**
  * \brief find affinity by its name
  * \retval a pointer to the affinity or NULL if not found
@@ -111,7 +113,7 @@ static void AffinitySetupInit()
         for (j = 0; j < ncpu; j++) {
             CPU_SET(j, cs);
         }
-       SCMutexInit(&thread_affinity[i].taf_mutex, NULL);
+        SCMutexInit(&thread_affinity[i].taf_mutex, NULL);
     }
     return;
 }
@@ -191,7 +193,10 @@ void AffinitySetupLoadFromConfig()
     ConfNode *root = ConfGetNode("threading.cpu-affinity");
     ConfNode *affinity;
 
-    AffinitySetupInit();
+    if (thread_affinity_init_done == 0) {
+        AffinitySetupInit();
+        thread_affinity_init_done = 1;
+    }
 
     SCLogDebug("Load affinity from config\n");
     if (root == NULL) {