aboutsummaryrefslogtreecommitdiffstats
path: root/epan/wmem/wmem_core.c
diff options
context:
space:
mode:
authorEvan Huus <eapache@gmail.com>2013-06-19 18:28:13 +0000
committerEvan Huus <eapache@gmail.com>2013-06-19 18:28:13 +0000
commite13d73e038b89cf1ab1b53764214fda825a0b83f (patch)
tree384d3d6d777a2118365ce9ed321b0f623461bd7f /epan/wmem/wmem_core.c
parent7670683e3be189c570213dba3e7e8697db1e5053 (diff)
Rework wmem scoping limits so that users can still get a handle to a pool when
it is out of scope, they just can't *allocate* in the pool. This is necessary because file-scope trees (migrating from emem) are set up on program initialization when there is no file in scope - they need to initialize with the handle, they just won't use it until a file is actually in scope. svn path=/trunk/; revision=50046
Diffstat (limited to 'epan/wmem/wmem_core.c')
-rw-r--r--epan/wmem/wmem_core.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/epan/wmem/wmem_core.c b/epan/wmem/wmem_core.c
index baaee5530e..ed5f73c4cc 100644
--- a/epan/wmem/wmem_core.c
+++ b/epan/wmem/wmem_core.c
@@ -42,6 +42,8 @@ wmem_alloc(wmem_allocator_t *allocator, const size_t size)
return g_malloc(size);
}
+ g_assert(allocator->in_scope);
+
if (size == 0) {
return NULL;
}
@@ -54,13 +56,11 @@ wmem_alloc0(wmem_allocator_t *allocator, const size_t size)
{
void *buf;
- if (size == 0) {
- return NULL;
- }
-
buf = wmem_alloc(allocator, size);
- memset(buf, 0, size);
+ if (buf) {
+ memset(buf, 0, size);
+ }
return buf;
}
@@ -73,6 +73,8 @@ wmem_free(wmem_allocator_t *allocator, void *ptr)
return;
}
+ g_assert(allocator->in_scope);
+
if (ptr == NULL) {
return;
}
@@ -96,6 +98,8 @@ wmem_realloc(wmem_allocator_t *allocator, void *ptr, const size_t size)
return NULL;
}
+ g_assert(allocator->in_scope);
+
return allocator->realloc(allocator->private_data, ptr, size);
}
@@ -159,8 +163,9 @@ wmem_allocator_new(const wmem_allocator_type_t type)
}
allocator = g_slice_new(wmem_allocator_t);
- allocator->type = real_type;
+ allocator->type = real_type;
allocator->callbacks = NULL;
+ allocator->in_scope = TRUE;
switch (real_type) {
case WMEM_ALLOCATOR_SIMPLE: