Add emem_init() which initializes both the ep_ and se_ allocators; have all

callers use that instead of initializing each allocator individually.

svn path=/trunk/; revision=30646
This commit is contained in:
Jeff Morriss 2009-10-20 17:43:05 +00:00
parent 8ec5a160ec
commit 78318b32ee
4 changed files with 40 additions and 34 deletions

View 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 };

View File

@ -28,6 +28,12 @@
#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
@ -39,10 +45,6 @@
* 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);

View 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();

View 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();