diff options
author | Evan Huus <eapache@gmail.com> | 2013-02-14 16:07:25 +0000 |
---|---|---|
committer | Evan Huus <eapache@gmail.com> | 2013-02-14 16:07:25 +0000 |
commit | 5071e8b6277238631c2123e1c56f31c0658bc61d (patch) | |
tree | 527e16e31374196fbab46c53e2ead1508d870cc0 | |
parent | c3c6ebe6c0f1a9b4ebc33b19509895abc88178d1 (diff) |
Add an option for bypassing the wmem slab similar to the one for
bypassing the emem slab, to aid in debugging with valgrind.
svn path=/trunk/; revision=47656
-rw-r--r-- | epan/wmem/wmem_slab.c | 14 | ||||
-rwxr-xr-x | tools/test-common.sh | 1 | ||||
-rwxr-xr-x | tools/valgrind-wireshark.sh | 1 |
3 files changed, 15 insertions, 1 deletions
diff --git a/epan/wmem/wmem_slab.c b/epan/wmem/wmem_slab.c index 9a32d80a40..556fb66396 100644 --- a/epan/wmem/wmem_slab.c +++ b/epan/wmem/wmem_slab.c @@ -23,6 +23,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include <stdlib.h> #include <string.h> #include <glib.h> @@ -34,13 +35,14 @@ typedef struct _wmem_slab_chunk_t { } wmem_slab_chunk_t; struct _wmem_slab_t { + gboolean debug; size_t chunk_size; wmem_slab_chunk_t *free_list; wmem_allocator_t *allocator; }; -/* arbitrary, nice round value */ +/* arbitrary, nice power-of-two value */ #define WMEM_CHUNKS_PER_ALLOC 8 static void @@ -68,6 +70,10 @@ wmem_slab_alloc(wmem_slab_t *slab) { wmem_slab_chunk_t *chunk; + if (slab->debug) { + return wmem_alloc(slab->allocator, slab->chunk_size); + } + if (slab->free_list == NULL) { wmem_slab_alloc_chunks(slab); } @@ -84,6 +90,11 @@ wmem_slab_free(wmem_slab_t *slab, void *object) wmem_slab_chunk_t *chunk; chunk = (wmem_slab_chunk_t *) object; + if (slab->debug) { + wmem_free(slab->allocator, chunk); + return; + } + chunk->next = slab->free_list; slab->free_list = chunk; } @@ -100,6 +111,7 @@ wmem_slab_new(wmem_allocator_t *allocator, const size_t chunk_size) sizeof(wmem_slab_chunk_t); slab->free_list = NULL; slab->allocator = allocator; + slab->debug = getenv("WIRESHARK_DEBUG_WMEM_SLAB") ? TRUE : FALSE; return slab; } diff --git a/tools/test-common.sh b/tools/test-common.sh index ee56b6e0ee..faa0155792 100755 --- a/tools/test-common.sh +++ b/tools/test-common.sh @@ -67,6 +67,7 @@ export WIRESHARK_EP_VERIFY_POINTERS= export WIRESHARK_SE_VERIFY_POINTERS= # Use the Wmem strict allocator which does canaries and scrubbing etc. export WIRESHARK_DEBUG_WMEM_OVERRIDE=strict +export WIRESHARK_DEBUG_WMEM_SLAB= # Turn on GLib memory debugging (since 2.13) export G_SLICE=debug-blocks diff --git a/tools/valgrind-wireshark.sh b/tools/valgrind-wireshark.sh index bd7a3d975a..d465148d61 100755 --- a/tools/valgrind-wireshark.sh +++ b/tools/valgrind-wireshark.sh @@ -80,6 +80,7 @@ fi export WIRESHARK_DEBUG_EP_NO_CHUNKS= export WIRESHARK_DEBUG_SE_NO_CHUNKS= export WIRESHARK_DEBUG_WMEM_OVERRIDE=simple +export WIRESHARK_DEBUG_WMEM_SLAB= export WIRESHARK_DEBUG_USE_SLICES= export G_SLICE=always-malloc # or debug-blocks |