[PATCH 3/5] dummy_malloc: Check if sbrk() fails

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 common/dummy_malloc.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/common/dummy_malloc.c b/common/dummy_malloc.c
index ab6712018..0120d9be2 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);
 }
 
-- 
2.17.1


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux