From 68a164dd7915d1e09048c82585ac39e43e49551f Mon Sep 17 00:00:00 2001 From: xianjimli Date: Thu, 22 Oct 2020 14:17:57 +0800 Subject: [PATCH] improve darray --- docs/changes.md | 1 + src/tkc/darray.c | 2 +- tests/darray_test.cc | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/changes.md b/docs/changes.md index 9880b9058..c4c3c56fd 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -2,6 +2,7 @@ 2020/10/22 * OpenGL 模式下的图片采样算法由相邻采样改为线性采样,主要为了提高图片旋转缩放效果(感谢智明提供补丁)。 + * 修改darray的elms为NULL是内存泄漏的问题(感谢兆坤提供补丁)。 2020/10/21 * awtk-web 修复编译报错问题(感谢智明提供补丁)。 diff --git a/src/tkc/darray.c b/src/tkc/darray.c index 0118a1989..151dfbf62 100644 --- a/src/tkc/darray.c +++ b/src/tkc/darray.c @@ -335,7 +335,7 @@ ret_t darray_deinit(darray_t* darray) { } ret_t darray_destroy(darray_t* darray) { - return_value_if_fail(darray != NULL && darray->elms != NULL, RET_BAD_PARAMS); + return_value_if_fail(darray != NULL, RET_BAD_PARAMS); darray_deinit(darray); TKMEM_FREE(darray); diff --git a/tests/darray_test.cc b/tests/darray_test.cc index 3369690c3..6063f074c 100644 --- a/tests/darray_test.cc +++ b/tests/darray_test.cc @@ -29,6 +29,14 @@ TEST(DArrayTest, create) { darray_destroy(darray); } +TEST(DArrayTest, create0) { + darray_t* darray = darray_create(0, NULL, NULL); + ASSERT_EQ(darray->size, 0); + ASSERT_EQ(darray->elms == NULL, true); + ASSERT_EQ(darray->capacity, 0); + darray_destroy(darray); +} + TEST(DArrayTest, stack) { char* p = NULL; darray_t* darray = darray_create(10, NULL, NULL);