From http://www.jwz.org/xscreensaver/xscreensaver-5.37.tar.gz
[xscreensaver] / utils / aligned_malloc.c
index c805b9e089c3b7270e7e04bac46d49dc49bcfb8d..b345ad1e586c209556c6e4fb6f8eba82c076d19f 100644 (file)
@@ -18,11 +18,13 @@ implied warranty.
 #include <stddef.h>
 #include <stdlib.h>
 
-#if !ALIGNED_MALLOC_HAS_MEMALIGN
-
 #include <assert.h>
 #include <errno.h>
 
+/* aligned_alloc() (C11) or posix_memalign() (POSIX) are other possibilities
+   for aligned_malloc().
+ */
+
 int aligned_malloc(void **ptr, unsigned alignment, size_t size)
 {
        void *block_start;
@@ -41,7 +43,6 @@ int aligned_malloc(void **ptr, unsigned alignment, size_t size)
 
 void aligned_free(void *ptr)
 {
-       free(((void **)(ptr))[-1]);
+       if(ptr)
+               free(((void **)(ptr))[-1]);
 }
-
-#endif