From e6018cd3b47ca094711ebeb8901509396235c20f Mon Sep 17 00:00:00 2001 From: Quyunfei Date: Sat, 6 May 2023 23:30:14 +0800 Subject: [PATCH] [HUST CSE] The memory leak is fixed --- components/libc/cplusplus/cpp11/emutls.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/components/libc/cplusplus/cpp11/emutls.c b/components/libc/cplusplus/cpp11/emutls.c index 52d1244c92..44d53a55df 100644 --- a/components/libc/cplusplus/cpp11/emutls.c +++ b/components/libc/cplusplus/cpp11/emutls.c @@ -188,11 +188,20 @@ emutls_get_address_array(uintptr_t index) { uintptr_t orig_size = array->size; uintptr_t new_size = emutls_new_data_array_size(index); - array = (emutls_address_array *)realloc(array, (new_size + 1) * sizeof(void *)); + emutls_address_array *array_temp = (emutls_address_array *)realloc(array, (new_size + 1) * sizeof(void *)); - if (array) + if (array_temp) + { + array = array_temp; memset(array->data + orig_size, 0, (new_size - orig_size) * sizeof(void *)); + } + else + { + free(array); + array = null; + } + emutls_check_array_set_size(array, new_size); } return array; -- Gitee