Browse Source

[update] 使用memheap内存管理时,rt_malloc 0长度返回RT_NULL, 与slab与小内存管理等算法保持一致。

zhouji 3 years ago
parent
commit
3327ffaa15
1 changed files with 4 additions and 0 deletions
  1. 4 0
      src/memheap.c

+ 4 - 0
src/memheap.c

@@ -850,6 +850,10 @@ void *rt_malloc(rt_size_t size)
 {
     void *ptr;
 
+    /* zero size, return RT_NULL */
+    if (size == 0)
+        return RT_NULL;
+
     /* try to allocate in system heap */
     ptr = rt_memheap_alloc(&_heap, size);
 #ifdef RT_USING_MEMHEAP_AUTO_BINDING