소스 검색

[Kernel] Fix rt_realloc issue when new size is 0.

armink 7 년 전
부모
커밋
a7e7b3dc02
1개의 변경된 파일6개의 추가작업 그리고 1개의 파일을 삭제
  1. 6 1
      src/mem.c

+ 6 - 1
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 */
-