[PATCH 5/6] dummy_malloc: fail allocations exceeding MALLOC_MAX_SIZE

Ahmad Fatoum a.fatoum at pengutronix.de
Thu Feb 20 12:30:31 PST 2025


For uniformity with the proper allocators, let's observe the same
maximum allocation size they do.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 common/dummy_malloc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/common/dummy_malloc.c b/common/dummy_malloc.c
index 140ba314272a..4973f35650ab 100644
--- a/common/dummy_malloc.c
+++ b/common/dummy_malloc.c
@@ -11,8 +11,10 @@ void malloc_stats(void)
 
 void *memalign(size_t alignment, size_t bytes)
 {
-	void *mem = sbrk(bytes + alignment);
+	void *mem = NULL;
 
+	if (alignment <= MALLOC_MAX_SIZE && bytes <= MALLOC_MAX_SIZE)
+		mem = sbrk(bytes + alignment);
 	if (!mem) {
 		errno = ENOMEM;
 		return NULL;
-- 
2.39.5




More information about the barebox mailing list