From a7e7b3dc0274975a6faec637ad2561412c0f0884 Mon Sep 17 00:00:00 2001 From: armink Date: Mon, 14 Aug 2017 15:57:42 +0800 Subject: [PATCH] [Kernel] Fix rt_realloc issue when new size is 0. --- src/mem.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/mem.c b/src/mem.c index b19e46d524..94e9474f7c 100644 --- a/src/mem.c +++ b/src/mem.c @@ -24,6 +24,7 @@ * fix memory check in rt_realloc function * 2010-07-13 Bernard fix RT_ALIGN issue found by kuronca * 2010-10-14 Bernard fix rt_realloc issue when realloc a NULL pointer. + * 2017-07-14 armink fix rt_realloc issue when new size is 0 */ /* @@ -400,6 +401,11 @@ void *rt_realloc(void *rmem, rt_size_t newsize) return RT_NULL; } + else if (newsize == 0) + { + rt_free(rmem); + return RT_NULL; + } /* allocate a new memory block */ if (rmem == RT_NULL) @@ -589,4 +595,3 @@ FINSH_FUNCTION_EXPORT(list_mem, list memory usage information) #endif /* end of RT_USING_HEAP */ #endif /* end of RT_USING_MEMHEAP_AS_HEAP */ -