You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ag...@apache.org on 2020/02/01 13:04:29 UTC
[incubator-nuttx] branch pr195 updated: Fix size zero
malloc()/realloc() freeze in the kernel build mode.
This is an automated email from the ASF dual-hosted git repository.
aguettouche pushed a commit to branch pr195
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/pr195 by this push:
new 32471fc Fix size zero malloc()/realloc() freeze in the kernel build mode.
32471fc is described below
commit 32471fcb840b833aaf56676eb83ba465f8cc0d7b
Author: Oki Minabe <mi...@gmail.com>
AuthorDate: Sat Feb 1 17:45:08 2020 +0900
Fix size zero malloc()/realloc() freeze in the kernel build mode.
---
mm/umm_heap/umm_malloc.c | 5 +++++
mm/umm_heap/umm_realloc.c | 6 ++++++
2 files changed, 11 insertions(+)
diff --git a/mm/umm_heap/umm_malloc.c b/mm/umm_heap/umm_malloc.c
index 7f38ac3..ea2f13e 100644
--- a/mm/umm_heap/umm_malloc.c
+++ b/mm/umm_heap/umm_malloc.c
@@ -70,6 +70,11 @@ FAR void *malloc(size_t size)
FAR void *brkaddr;
FAR void *mem;
+ if (size < 1)
+ {
+ return NULL;
+ }
+
/* Loop until we successfully allocate the memory or until an error
* 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
diff --git a/mm/umm_heap/umm_realloc.c b/mm/umm_heap/umm_realloc.c
index 5538bf5..0a27df4 100644
--- a/mm/umm_heap/umm_realloc.c
+++ b/mm/umm_heap/umm_realloc.c
@@ -71,6 +71,12 @@ FAR void *realloc(FAR void *oldmem, size_t size)
FAR void *brkaddr;
FAR void *mem;
+ if (size < 1)
+ {
+ mm_free(USR_HEAP, oldmem);
+ return NULL;
+ }
+
/* Loop until we successfully allocate the memory or until an error
* 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