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
}

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"
@ -86,6 +86,14 @@ FAR void *memalign(size_t alignment, size_t size)
return mem;
#else
return mm_memalign(USR_HEAP, alignment, size);
FAR void *ret;
ret = mm_memalign(USR_HEAP, alignment, size);
if (!ret)
{
set_errno(ENOMEM);
}
return ret;
#endif
}

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"
@ -88,6 +88,14 @@ FAR void *realloc(FAR void *oldmem, size_t size)
return mem;
#else
return mm_realloc(USR_HEAP, oldmem, size);
FAR void *ret;
ret = mm_realloc(USR_HEAP, oldmem, size);
if (!ret)
{
set_errno(ENOMEM);
}
return ret;
#endif
}

View File

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