fix(mem): fix TLSF returning the wrong pointer when the requested size is too large (#3325)

* test(mem) add test for #3324

* fix(tlsf) don't return the same pointer if the requested size is too large
This commit is contained in:
embeddedt
2022-05-14 16:04:13 -04:00
committed by GitHub
parent 0d6c08105a
commit 2148ed99b0
2 changed files with 30 additions and 0 deletions

View File

@@ -1208,6 +1208,10 @@ void * lv_tlsf_realloc(lv_tlsf_t tlsf, void * ptr, size_t size)
const size_t cursize = block_size(block);
const size_t combined = cursize + block_size(next) + block_header_overhead;
const size_t adjust = adjust_request_size(size, ALIGN_SIZE);
if(size > cursize && adjust == 0) {
/* The request is probably too large, fail */
return NULL;
}
tlsf_assert(!block_is_free(block) && "block already marked as free");

View File

@@ -0,0 +1,26 @@
#if LV_BUILD_TEST
#include "../lvgl.h"
#include "unity/unity.h"
void setUp(void)
{
/* Function run before every test */
}
void tearDown(void)
{
/* Function run after every test */
}
/* #3324 */
void test_mem_buf_realloc(void)
{
#if LV_MEM_CUSTOM == 0
void * buf1 = lv_mem_alloc(20);
void * buf2 = lv_mem_realloc(buf1, LV_MEM_SIZE + 16384);
TEST_ASSERT_NULL(buf2);
#endif
}
#endif