aboutsummaryrefslogtreecommitdiffstats
path: root/epan/wmem/wmem_core.c
diff options
context:
space:
mode:
authorEvan Huus <eapache@gmail.com>2012-12-19 00:43:36 +0000
committerEvan Huus <eapache@gmail.com>2012-12-19 00:43:36 +0000
commit5cf858ec52d1f3a05fcaa43ac0571d321244a87e (patch)
treed2a49636b7fd471647f1f2a0635be5ca45903c17 /epan/wmem/wmem_core.c
parent561525cbb538b030d28aa4951cf77c9f3f286954 (diff)
Dispatch all allocator creations through a single function using an enum to
determine the desired type. This has two advantages over the old way: - just one environment variable for valgrind to override in order to guarantee that ALL allocators use memory it can track, and just one place to check that variable - allocator owners no longer have to include headers specific to their allocator, allowing them to change allocators without adjusting all their #includes svn path=/trunk/; revision=46604
Diffstat (limited to 'epan/wmem/wmem_core.c')
-rw-r--r--epan/wmem/wmem_core.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/epan/wmem/wmem_core.c b/epan/wmem/wmem_core.c
index 82bde49ca1..9946c70a53 100644
--- a/epan/wmem/wmem_core.c
+++ b/epan/wmem/wmem_core.c
@@ -23,11 +23,15 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include <stdlib.h>
#include <string.h>
+#include <glib.h>
#include "wmem_core.h"
#include "wmem_scopes.h"
#include "wmem_allocator.h"
+#include "wmem_allocator_simple.h"
+#include "wmem_allocator_block.h"
void *
wmem_alloc(wmem_allocator_t *allocator, const size_t size)
@@ -58,6 +62,27 @@ wmem_destroy_allocator(wmem_allocator_t *allocator)
allocator->destroy(allocator);
}
+wmem_allocator_t *
+wmem_allocator_new(const wmem_allocator_type_t type)
+{
+ /* Our valgrind script uses this environment variable to override the
+ * usual allocator choice so that everything goes through system-level
+ * allocations that it understands and can track. Otherwise it will get
+ * confused by the block allocator etc. */
+ if (getenv("WIRESHARK_DEBUG_WMEM_SIMPLE")) {
+ return wmem_simple_allocator_new();
+ }
+
+ switch (type) {
+ case WMEM_ALLOCATOR_SIMPLE:
+ return wmem_simple_allocator_new();
+ case WMEM_ALLOCATOR_BLOCK:
+ return wmem_block_allocator_new();
+ default:
+ g_assert_not_reached();
+ };
+}
+
void
wmem_init(void)
{