mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 11:56:10 +08:00
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:
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <nuttx/mm/mm.h>
|
#include <nuttx/mm/mm.h>
|
||||||
|
|
||||||
#include "umm_heap/umm_heap.h"
|
#include "umm_heap/umm_heap.h"
|
||||||
@@ -57,8 +57,16 @@ FAR void *malloc(size_t size)
|
|||||||
|
|
||||||
return memalign(sizeof(FAR void *), size);
|
return memalign(sizeof(FAR void *), size);
|
||||||
#else
|
#else
|
||||||
|
FAR void *ret;
|
||||||
|
|
||||||
/* Use mm_malloc() because it implements the clear */
|
/* 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
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <nuttx/mm/mm.h>
|
#include <nuttx/mm/mm.h>
|
||||||
|
|
||||||
#include "umm_heap/umm_heap.h"
|
#include "umm_heap/umm_heap.h"
|
||||||
@@ -86,6 +86,14 @@ FAR void *memalign(size_t alignment, size_t size)
|
|||||||
|
|
||||||
return mem;
|
return mem;
|
||||||
#else
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <nuttx/mm/mm.h>
|
#include <nuttx/mm/mm.h>
|
||||||
|
|
||||||
#include "umm_heap/umm_heap.h"
|
#include "umm_heap/umm_heap.h"
|
||||||
@@ -88,6 +88,14 @@ FAR void *realloc(FAR void *oldmem, size_t size)
|
|||||||
|
|
||||||
return mem;
|
return mem;
|
||||||
#else
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <nuttx/mm/mm.h>
|
#include <nuttx/mm/mm.h>
|
||||||
|
|
||||||
#include "umm_heap/umm_heap.h"
|
#include "umm_heap/umm_heap.h"
|
||||||
@@ -63,8 +63,16 @@ FAR void *zalloc(size_t size)
|
|||||||
|
|
||||||
return mem;
|
return mem;
|
||||||
#else
|
#else
|
||||||
|
FAR void *ret;
|
||||||
|
|
||||||
/* Use mm_zalloc() because it implements the clear */
|
/* 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
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user