aboutsummaryrefslogtreecommitdiffstats
path: root/epan/wmem
diff options
context:
space:
mode:
authorEvan Huus <eapache@gmail.com>2013-12-24 01:17:41 +0000
committerEvan Huus <eapache@gmail.com>2013-12-24 01:17:41 +0000
commit1dfa4e2697c058482d29ae6985583e3a99ff31f1 (patch)
tree65d72e6aedb0740bf23a8bd73101dd281e137767 /epan/wmem
parent5f91a0afc7aabda4670bfb20616af6cbbfd0360d (diff)
Add wmem_destroy_list, wmem_destroy_queue, wmem_destroy_stack so that those
data-structures can be used with manually managed memory. svn path=/trunk/; revision=54432
Diffstat (limited to 'epan/wmem')
-rw-r--r--epan/wmem/wmem_list.c16
-rw-r--r--epan/wmem/wmem_list.h4
-rw-r--r--epan/wmem/wmem_queue.h2
-rw-r--r--epan/wmem/wmem_stack.h2
-rw-r--r--epan/wmem/wmem_test.c11
5 files changed, 35 insertions, 0 deletions
diff --git a/epan/wmem/wmem_list.c b/epan/wmem/wmem_list.c
index df9f07ceee..592d51b432 100644
--- a/epan/wmem/wmem_list.c
+++ b/epan/wmem/wmem_list.c
@@ -173,6 +173,22 @@ wmem_list_new(wmem_allocator_t *allocator)
return list;
}
+void
+wmem_destroy_list(wmem_list_t *list)
+{
+ wmem_list_frame_t *cur, *next;
+
+ cur = list->head;
+
+ while (cur) {
+ next = cur->next;
+ wmem_free(list->allocator, cur);
+ cur = next;
+ }
+
+ wmem_free(list->allocator, list);
+}
+
/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*
diff --git a/epan/wmem/wmem_list.h b/epan/wmem/wmem_list.h
index 65bd0073db..a753070a47 100644
--- a/epan/wmem/wmem_list.h
+++ b/epan/wmem/wmem_list.h
@@ -95,6 +95,10 @@ wmem_list_t *
wmem_list_new(wmem_allocator_t *allocator)
G_GNUC_MALLOC;
+WS_DLL_PUBLIC
+void
+wmem_destroy_list(wmem_list_t *list);
+
/** @}
* @} */
diff --git a/epan/wmem/wmem_queue.h b/epan/wmem/wmem_queue.h
index c79489402c..90090c01d2 100644
--- a/epan/wmem/wmem_queue.h
+++ b/epan/wmem/wmem_queue.h
@@ -58,6 +58,8 @@ typedef wmem_list_t wmem_queue_t;
#define wmem_queue_new(ALLOCATOR) wmem_list_new(ALLOCATOR)
+#define wmem_destroy_queue(QUEUE) wmem_destroy_list(QUEUE)
+
/** @}
* @} */
diff --git a/epan/wmem/wmem_stack.h b/epan/wmem/wmem_stack.h
index e2435c9b96..7cc667126b 100644
--- a/epan/wmem/wmem_stack.h
+++ b/epan/wmem/wmem_stack.h
@@ -62,6 +62,8 @@ wmem_stack_pop(wmem_stack_t *stack);
#define wmem_stack_new(ALLOCATOR) wmem_list_new(ALLOCATOR)
+#define wmem_destroy_stack(STACK) wmem_destroy_list(STACK)
+
/** @}
* @} */
diff --git a/epan/wmem/wmem_test.c b/epan/wmem/wmem_test.c
index 00139ef4a7..6e83e4b322 100644
--- a/epan/wmem/wmem_test.c
+++ b/epan/wmem/wmem_test.c
@@ -593,6 +593,13 @@ wmem_test_list(void)
}
wmem_destroy_allocator(allocator);
+
+ list = wmem_list_new(NULL);
+ for (i=0; i<CONTAINER_ITERS; i++) {
+ wmem_list_prepend(list, GINT_TO_POINTER(i));
+ }
+ g_assert(wmem_list_count(list) == CONTAINER_ITERS);
+ wmem_destroy_list(list);
}
static void
@@ -623,6 +630,8 @@ wmem_test_queue(void)
}
g_assert(wmem_queue_count(queue) == 0);
+ wmem_destroy_queue(queue);
+
wmem_destroy_allocator(allocator);
}
@@ -654,6 +663,8 @@ wmem_test_stack(void)
}
g_assert(wmem_stack_count(stack) == 0);
+ wmem_destroy_stack(stack);
+
wmem_destroy_allocator(allocator);
}