From 058c263f6bd41ffa18328e0ff60d25d3a028f975 Mon Sep 17 00:00:00 2001 From: Kito Cheng Date: Thu, 23 Feb 2017 17:16:28 +0800 Subject: Only set *memptr when success for posix_memalign --- libc/stdlib/posix_memalign.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'libc') diff --git a/libc/stdlib/posix_memalign.c b/libc/stdlib/posix_memalign.c index 523bc2cbd..01831070f 100644 --- a/libc/stdlib/posix_memalign.c +++ b/libc/stdlib/posix_memalign.c @@ -34,8 +34,10 @@ int posix_memalign(void **memptr, size_t alignment, size_t size) || alignment == 0 */ return EINVAL; - - *memptr = memalign(alignment, size); - - return (*memptr != NULL ? 0 : ENOMEM); + void *mem = memalign(alignment, size); + if (mem != NULL) { + *memptr = mem; + return 0; + } else + return ENOMEM; } -- cgit v1.2.3