diff --git a/components/libc/cplusplus/cpp11/emutls.c b/components/libc/cplusplus/cpp11/emutls.c index 52d1244c92a0bcccd8f6ee42488119f992a87428..44d53a55dffd25549cf6e43dd6e2863c9b7d0da1 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;