summaryrefslogtreecommitdiffstats
path: root/common/dummy_malloc.c
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2018-10-15 10:00:19 -0700
committerSascha Hauer <s.hauer@pengutronix.de>2018-10-16 09:04:08 +0200
commit7bcf295e8db48474f2ad4e37c7cccc3550fc2904 (patch)
treed16398457b061ee976f37a1d581abab5d0578b6c /common/dummy_malloc.c
parent5daab6ebb368eb4b113da858b9d9e12b8d670c52 (diff)
downloadbarebox-7bcf295e8db48474f2ad4e37c7cccc3550fc2904.tar.gz
dummy_malloc: Check if sbrk() fails
Add code to check if sbrk() fails as well as setting appropriate 'errno' for users that may rely on it for error reporting. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/dummy_malloc.c')
-rw-r--r--common/dummy_malloc.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/common/dummy_malloc.c b/common/dummy_malloc.c
index ab67120..0120d9b 100644
--- a/common/dummy_malloc.c
+++ b/common/dummy_malloc.c
@@ -32,6 +32,11 @@ void *memalign(size_t alignment, size_t bytes)
{
void *mem = sbrk(bytes + alignment);
+ if (!mem) {
+ errno = ENOMEM;
+ return NULL;
+ }
+
return PTR_ALIGN(mem, alignment);
}