malloc: set errno to ENOMEM when malloc fail

fix LTP case ltp_threads_pthread_cond_init_s_c error:
"Test ltp_threads_pthread_cond_init_s_c unresolved: got 38
(Invalid system call number) on line 236 (Memory not full)"

Signed-off-by: yangyalei <yangyalei@xiaomi.com>

ltp: fix review questions

Signed-off-by: yangyalei <yangyalei@xiaomi.com>
This commit is contained in:
yangyalei
2023-06-15 10:38:38 +08:00
committed by Xiang Xiao
parent f2844a2e3c
commit a551be4ee2
4 changed files with 40 additions and 8 deletions

View File

@@ -26,7 +26,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <nuttx/mm/mm.h>
#include "umm_heap/umm_heap.h"
@@ -57,8 +57,16 @@ FAR void *malloc(size_t size)
return memalign(sizeof(FAR void *), size);
#else
FAR void *ret;
/* Use mm_malloc() because it implements the clear */
return mm_malloc(USR_HEAP, size);
ret = mm_malloc(USR_HEAP, size);
if (!ret)
{
set_errno(ENOMEM);
}
return ret;
#endif
}