mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 11:26:12 +08:00
mm/umm_heap/: Handle size zero in umm_malloc.c and umm_realloc.c, which causes a system freeze in kernel mode.
This commit is contained in:
@@ -70,6 +70,11 @@ FAR void *malloc(size_t size)
|
|||||||
FAR void *brkaddr;
|
FAR void *brkaddr;
|
||||||
FAR void *mem;
|
FAR void *mem;
|
||||||
|
|
||||||
|
if (size < 1)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Loop until we successfully allocate the memory or until an error
|
/* Loop until we successfully allocate the memory or until an error
|
||||||
* occurs. If we fail to allocate memory on the first pass, then call
|
* occurs. If we fail to allocate memory on the first pass, then call
|
||||||
* sbrk to extend the heap by one page. This may require several
|
* sbrk to extend the heap by one page. This may require several
|
||||||
|
|||||||
@@ -71,6 +71,12 @@ FAR void *realloc(FAR void *oldmem, size_t size)
|
|||||||
FAR void *brkaddr;
|
FAR void *brkaddr;
|
||||||
FAR void *mem;
|
FAR void *mem;
|
||||||
|
|
||||||
|
if (size < 1)
|
||||||
|
{
|
||||||
|
mm_free(USR_HEAP, oldmem);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Loop until we successfully allocate the memory or until an error
|
/* Loop until we successfully allocate the memory or until an error
|
||||||
* occurs. If we fail to allocate memory on the first pass, then call
|
* occurs. If we fail to allocate memory on the first pass, then call
|
||||||
* sbrk to extend the heap by one page. This may require several
|
* sbrk to extend the heap by one page. This may require several
|
||||||
|
|||||||
Reference in New Issue
Block a user