From 0e8f26743214b903f66eb732e4a8c151213d61e1 Mon Sep 17 00:00:00 2001 From: sanine Date: Tue, 28 Sep 2021 22:44:30 -0500 Subject: add mock_queue_cleanup() function and move queue malloc call inside mock_queue_data --- src/test/mock_queue.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/test/mock_queue.c') diff --git a/src/test/mock_queue.c b/src/test/mock_queue.c index 10ce834..7a36b65 100644 --- a/src/test/mock_queue.c +++ b/src/test/mock_queue.c @@ -1,5 +1,6 @@ #include #include +#include #include "mock_queue.h" @@ -35,7 +36,13 @@ void mock_queue_data(size_t size, void *data) return; } - node->data = data; + node->data = malloc(size); + if (node->data == NULL) { + fprintf(stderr, "WARNING: memory allocation of %zu bytes for mock queue data failed!\n", size); + return; + } + + memcpy(node->data, data, size); node->next = NULL; mock_queue_tail->next = node; mock_queue_tail = node; @@ -67,3 +74,10 @@ void mock_pop() mock_queue_tail = &mock_queue_head; mock_queue_length -= 1; } + + +void mock_queue_cleanup() +{ + while(mock_queue_length != 0) + mock_pop(); +} -- cgit v1.2.1