From: Phil Carmody Date: Thu, 30 Aug 2018 08:36:08 +0000 (+0300) Subject: lib: test-array - tests that freeing without data doesn't free the data X-Git-Tag: 2.3.9~1487 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8294e0c20dfda55280271b26310625f39470ec1;p=thirdparty%2Fdovecot%2Fcore.git lib: test-array - tests that freeing without data doesn't free the data Signed-off-by: Phil Carmody --- diff --git a/src/lib/test-array.c b/src/lib/test-array.c index 928ab0f29b..1fa8003f08 100644 --- a/src/lib/test-array.c +++ b/src/lib/test-array.c @@ -280,6 +280,35 @@ static void test_array_cmp_str(void) test_end(); } +static void +test_array_free_case(bool keep) +{ + pool_t pool = pool_allocfree_create("array test"); + ARRAY(int) r; + int *p; + + test_begin(keep ? "array_free" : "array_free_without_data"); + + p_array_init(&r, pool, 100); + p = array_append_space(&r); + if (keep) { + p = array_free_without_data(&r); + test_assert(pool_allocfree_get_total_used_size(pool)>=400); + p_free(pool, p); + } else { + array_free(&r); + test_assert(pool_allocfree_get_total_used_size(pool)==0); + } + pool_unref(&pool); + test_end(); +} +static void +test_array_free(void) +{ + test_array_free_case(FALSE); + test_array_free_case(TRUE); +} + void test_array(void) { test_array_count(); @@ -290,6 +319,7 @@ void test_array(void) test_array_cmp(); test_array_cmp_str(); test_array_swap(); + test_array_free(); } enum fatal_test_state fatal_array(unsigned int stage)