summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Huus <eapache@gmail.com>2012-10-27 02:42:05 +0000
committerEvan Huus <eapache@gmail.com>2012-10-27 02:42:05 +0000
commitb464dcd8888d1cd8ad4e16022d358d555a27f4fd (patch)
tree2a100927c562fe065e682b54113cd63f4a1582f2
parent2ea364607a49c3c73ba0ddadf4ed88e7bf9bce98 (diff)
downloadwireshark-b464dcd8888d1cd8ad4e16022d358d555a27f4fd.tar.gz
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
-rw-r--r--epan/epan.c5
-rw-r--r--epan/wmem/wmem_core.c21
-rw-r--r--epan/wmem/wmem_core.h9
3 files changed, 34 insertions, 1 deletions
diff --git a/epan/epan.c b/epan/epan.c
index 2de4da2938..6e64eece2b 100644
--- a/epan/epan.c
+++ b/epan/epan.c
@@ -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
diff --git a/epan/wmem/wmem_core.c b/epan/wmem/wmem_core.c
index 1da5328c36..5dcb8ed559 100644
--- a/epan/wmem/wmem_core.c
+++ b/epan/wmem/wmem_core.c
@@ -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
*
diff --git a/epan/wmem/wmem_core.h b/epan/wmem/wmem_core.h
index 4de4e6eb60..8d7753d54c 100644
--- a/epan/wmem/wmem_core.h
+++ b/epan/wmem/wmem_core.h
@@ -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 */