From 9a74a4d9c970bf6b49d2c15d284ca190451d5ef6 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Mon, 17 Mar 2014 16:11:16 +0100 Subject: [PATCH] Check return value for posix_memalign. --- src/simix/smx_context.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/simix/smx_context.c b/src/simix/smx_context.c index 833ca8414a..0bfad29665 100644 --- a/src/simix/smx_context.c +++ b/src/simix/smx_context.c @@ -120,10 +120,13 @@ void *SIMIX_context_stack_new(void) stack = alloc - ((uintptr_t)alloc & (xbt_pagesize - 1)) + xbt_pagesize; *((void **)stack - 1) = alloc; #else - posix_memalign(&stack, xbt_pagesize, size); + if (posix_memalign(&stack, xbt_pagesize, size) != 0) + xbt_die("Failed to allocate stack."); #endif - if (!stack || mprotect(stack, smx_context_guard_size, PROT_NONE) == -1) - xbt_die("Failed to allocate stack: %s", strerror(errno)); + if (mprotect(stack, smx_context_guard_size, PROT_NONE) == -1) { + XBT_WARN("Failed to protect stack: %s", strerror(errno)); + /* That's not fatal, pursue anyway. */ + } stack = (char *)stack + smx_context_guard_size; } else { stack = xbt_malloc0(smx_context_stack_size); @@ -154,9 +157,10 @@ void SIMIX_context_stack_delete(void *stack) if (smx_context_guard_size > 0 && !MC_is_active()) { stack = (char *)stack - smx_context_guard_size; if (mprotect(stack, smx_context_guard_size, - PROT_READ | PROT_WRITE | PROT_EXEC) == -1) + PROT_READ | PROT_WRITE | PROT_EXEC) == -1) { XBT_WARN("Failed to remove page protection: %s", strerror(errno)); - /* try to pursue anyway */ + /* try to pursue anyway */ + } #ifdef HAVE_MC /* Retrieve the saved pointer. See SIMIX_context_stack_new above. */ stack = *((void **)stack - 1); -- 2.20.1