Create init and cleanup functions for wmem as a whole.

Call them from epan_init() and epan_cleanup().
Expose a permanent wmem scope for allocations that should only be freed when
epan is done (which is *not* necessarily when the program finishes).

svn path=/trunk/; revision=45805
This commit is contained in:
Evan Huus 2012-10-27 02:42:05 +00:00
parent 2ea364607a
commit b464dcd888
3 changed files with 34 additions and 1 deletions

View File

@ -50,6 +50,7 @@
#include "addr_resolv.h"
#include "oids.h"
#include "emem.h"
#include "wmem/wmem.h"
#include "expert.h"
#ifdef HAVE_LUA
@ -83,8 +84,9 @@ epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_da
init_report_err(report_failure_fcn_p, report_open_failure_fcn_p,
report_read_failure_fcn_p, report_write_failure_fcn_p);
/* initialize memory allocation subsystem */
/* initialize memory allocation subsystems */
emem_init();
wmem_init();
/* initialize the GUID to name mapping table */
guids_init();
@ -127,6 +129,7 @@ epan_cleanup(void)
#endif
except_deinit();
host_name_lookup_cleanup();
wmem_cleanup();
}
void

View File

@ -27,6 +27,9 @@
#include "wmem_core.h"
#include "wmem_allocator.h"
#include "wmem_allocator_glib.h"
static wmem_allocator_t *permanent_scope;
void *
wmem_alloc(wmem_allocator_t *allocator, size_t size)
@ -57,6 +60,24 @@ wmem_destroy_allocator(wmem_allocator_t *allocator)
allocator->destroy(allocator);
}
wmem_allocator_t *
wmem_permanent_scope(void)
{
return permanent_scope;
}
void
wmem_init(void)
{
permanent_scope = wmem_create_glib_allocator();
}
void
wmem_cleanup(void)
{
wmem_destroy_allocator(permanent_scope);
}
/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*

View File

@ -48,6 +48,15 @@ wmem_free_all(wmem_allocator_t *allocator);
void
wmem_destroy_allocator(wmem_allocator_t *allocator);
wmem_allocator_t *
wmem_permanent_scope(void);
void
wmem_init(void);
void
wmem_cleanup(void);
#ifdef __cplusplus
}
#endif /* __cplusplus */