Browse Source

Only set *memptr when success for posix_memalign

Kito Cheng 7 years ago
parent
commit
058c263f6b
1 changed files with 6 additions and 4 deletions
  1. 6 4
      libc/stdlib/posix_memalign.c

+ 6 - 4
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;
 }