From d231a0f055da5a729145c25aadd753c0cb1d2001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20LUDWIG?= Date: Thu, 3 Aug 2023 19:42:50 +0200 Subject: [PATCH] feat: add array_list_free --- lib/array_list.c | 5 +++++ lib/array_list.h | 6 ++++++ test/array_list_test.c | 2 ++ 3 files changed, 13 insertions(+) diff --git a/lib/array_list.c b/lib/array_list.c index 194060e..5733c64 100644 --- a/lib/array_list.c +++ b/lib/array_list.c @@ -37,3 +37,8 @@ void* array_list_get(struct array_list* list, size_t index) { } return list->data[index]; } + +void array_list_free(struct array_list* list) { + free(list->data); + free(list); +} diff --git a/lib/array_list.h b/lib/array_list.h index 7279d5d..1c96b9e 100644 --- a/lib/array_list.h +++ b/lib/array_list.h @@ -42,4 +42,10 @@ void array_list_remove(struct array_list* list, size_t index); */ void* array_list_get(struct array_list* list, size_t index); +/** + * @brief Frees the array list. + * @since v2.1.0 + */ +void array_list_free(struct array_list* list); + #endif diff --git a/test/array_list_test.c b/test/array_list_test.c index 0366f23..9c1b4a6 100644 --- a/test/array_list_test.c +++ b/test/array_list_test.c @@ -32,4 +32,6 @@ void array_list_test() { array_list_remove(list, 100); assert(list->size == 105); assert(array_list_get(list, 100) == (void *)95); + + array_list_free(list); }