Add emem_init() which initializes both the ep_ and se_ allocators; have all
authormorriss <morriss@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 20 Oct 2009 17:43:05 +0000 (17:43 +0000)
committermorriss <morriss@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 20 Oct 2009 17:43:05 +0000 (17:43 +0000)
callers use that instead of initializing each allocator individually.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@30646 f5534014-38df-0310-8fa8-9805f1628bb7

epan/emem.c
epan/emem.h
epan/epan.c
epan/reassemble_test.c

index 9fb6fb3a952fc0a65305645fc4ea0c47deb4b976..dc8d11b48048dcc0ff03077275909cfa81e9a858 100644 (file)
@@ -257,7 +257,7 @@ emem_init_chunk(emem_header_t *mem)
  * This function should be called only once when Wireshark or TShark starts
  * up.
  */
-void
+static void
 ep_init_chunk(void)
 {
        ep_packet_mem.free_list=NULL;
@@ -272,6 +272,37 @@ ep_init_chunk(void)
 #endif
 
        emem_init_chunk(&ep_packet_mem);
+}
+
+/* Initialize the capture-lifetime memory allocation pool.
+ * This function should be called only once when Wireshark or TShark starts
+ * up.
+ */
+static void
+se_init_chunk(void)
+{
+       se_packet_mem.free_list = NULL;
+       se_packet_mem.used_list = NULL;
+       ep_packet_mem.trees = NULL;
+
+       se_packet_mem.debug_use_chunks = (getenv("WIRESHARK_DEBUG_SE_NO_CHUNKS") == NULL);
+       se_packet_mem.debug_use_canary = se_packet_mem.debug_use_chunks && (getenv("WIRESHARK_DEBUG_SE_USE_CANARY") != NULL);
+
+       emem_init_chunk(&se_packet_mem);
+}
+
+/*  Initialize all the allocators here.
+ *  This function should be called only once when Wireshark or TShark starts
+ *  up.
+ */
+void
+emem_init(void)
+{
+       ep_init_chunk();
+       se_init_chunk();
+
+       if (getenv("WIRESHARK_DEBUG_SCRUB_MEMORY"))
+               debug_use_memory_scrubber  = TRUE;
 
 #if defined (_WIN32)
        /* Set up our guard page info for Win32 */
@@ -298,27 +329,6 @@ ep_init_chunk(void)
 #endif /* _WIN32 / USE_GUARD_PAGES */
 }
 
-/* Initialize the capture-lifetime memory allocation pool.
- * This function should be called only once when Wireshark or TShark starts
- * up.
- */
-void
-se_init_chunk(void)
-{
-       se_packet_mem.free_list = NULL;
-       se_packet_mem.used_list = NULL;
-       ep_packet_mem.trees = NULL;
-
-       se_packet_mem.debug_use_chunks = (getenv("WIRESHARK_DEBUG_SE_NO_CHUNKS") == NULL);
-       se_packet_mem.debug_use_canary = se_packet_mem.debug_use_chunks && (getenv("WIRESHARK_DEBUG_SE_USE_CANARY") != NULL);
-
-       emem_init_chunk(&se_packet_mem);
-
-       /* This isn't specific to se_ memory, but need to init it somewhere.. */
-       if (getenv("WIRESHARK_DEBUG_SCRUB_MEMORY"))
-               debug_use_memory_scrubber  = TRUE;
-}
-
 #ifdef SHOW_EMEM_STATS
 #define NUM_ALLOC_DIST 10
 static guint allocations[NUM_ALLOC_DIST] = { 0 };
index d8e3cfaff0ad78c3aa091289460973930844187f..374a6f587dd11668c54927ae2bb6061fa2f6505e 100644 (file)
 
 #include "gnuc_format_check.h"
 
+/*  Initialize all the memory allocation pools described below.
+ *  This function must be called once when *shark initialize to set up the
+ *  required structures.
+ */
+void emem_init(void);
+
 /* Functions for handling memory allocation and garbage collection with
  * a packet lifetime scope.
  * These functions are used to allocate memory that will only remain persistent
  * Everytime a new packet is dissected, all memory allocations done in
  * the previous packet is freed.
  */
-/* Initialize packet-lifetime memory allocation pool. This function is called
- * once when [t]Wireshark is initialized to set up the required structures.
- */
-void ep_init_chunk(void);
 
 /* Allocate memory with a packet lifetime scope */
 void *ep_alloc(size_t size);
@@ -128,10 +130,6 @@ void* ep_stack_pop(ep_stack_t stack);
  *
  * These functions are very fast and offer automatic garbage collection.
  */
-/* Initialize capture-lifetime memory allocation pool. This function is called
- * once when [t]Wireshark is initialized to set up the required structures.
- */
-void se_init_chunk(void);
 
 /* Allocate memory with a capture lifetime scope */
 void *se_alloc(size_t size);
index 5d159852d169dd055289d78f7f541f08fad6160e..f59decee0e1aa565b364c1bfa14bc2572fc6fd23 100644 (file)
@@ -82,8 +82,7 @@ epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_da
            report_read_failure, report_write_failure);
 
        /* initialize memory allocation subsystem */
-       ep_init_chunk();
-       se_init_chunk();
+       emem_init();
 
        /* initialize the GUID to name mapping table */
        guids_init();
index a5030f5dd26557c73a580ba1b00ce69c468a0cd2..17689394070dedcbf41abd366babf5ca20333193 100644 (file)
@@ -1030,8 +1030,7 @@ main(int argc _U_, char **argv _U_)
     };
 
     /* initialise stuff */
-    ep_init_chunk();
-    se_init_chunk();
+    emem_init();
     tvbuff_init();
     reassemble_init();