core: add aligned_free to match the aligned_alloc used in the code
authorSteve Lhomme <robux4@videolabs.io>
Wed, 21 Jun 2017 13:05:30 +0000 (15:05 +0200)
committerThomas Guillem <thomas@gllm.fr>
Thu, 22 Jun 2017 07:15:07 +0000 (09:15 +0200)
On Windows if you allocate aligned memory you need to free it with an aligned
version of free.

This is similar to the old vlc_memalign() + vlc_free()

Signed-off-by: Thomas Guillem <thomas@gllm.fr>
compat/aligned_alloc.c
include/vlc_common.h
include/vlc_fixups.h
modules/video_chroma/copy.c
modules/video_filter/gradfun.c
modules/video_output/evas.c
src/misc/picture.c
src/misc/picture_pool.c

index 9ea352b..02881ee 100644 (file)
@@ -25,7 +25,7 @@
 #include <assert.h>
 #include <stdlib.h>
 #include <errno.h>
-#if !defined (HAVE_POSIX_MEMALIGN) && !defined (_WIN32)
+#if !defined (HAVE_POSIX_MEMALIGN)
 # include <malloc.h>
 #endif
 
@@ -52,14 +52,16 @@ void *aligned_alloc(size_t align, size_t size)
     }
     return ptr;
 
-#elif !defined (_WIN32)
-
-   return memalign(align, size);
-
+#elif defined(HAVE_MEMALIGN)
+    return memalign(align, size);
+#elif defined (_WIN32) && defined(__MINGW32__)
+    return __mingw_aligned_malloc(size, align);
+#elif defined (_WIN32) && defined(_MSC_VER)
+    return _aligned_malloc(size, align);
 #else
-
-   if (size > 0)
-       errno = ENOMEM;
-   return NULL;
+#warning unsupported aligned allocation!
+    if (size > 0)
+        errno = ENOMEM;
+    return NULL;
 #endif
 }
index 35655b1..94ab07e 100644 (file)
@@ -845,16 +845,6 @@ VLC_API bool vlc_ureduce( unsigned *, unsigned *, uint64_t, uint64_t, uint64_t )
 #define container_of(ptr, type, member) \
     ((type *)(((char *)(ptr)) - offsetof(type, member)))
 
-/* Aligned memory allocator */
-
-#ifdef __MINGW32__
-# define vlc_memalign(align, size) (__mingw_aligned_malloc(size, align))
-#elif defined(_MSC_VER)
-# define vlc_memalign(align, size) (_aligned_malloc(size, align))
-#else
-# define vlc_memalign(align, size) aligned_alloc(align, size)
-#endif
-
 /*****************************************************************************
  * I18n stuff
  *****************************************************************************/
index 44b8426..eb0eb17 100644 (file)
@@ -306,6 +306,14 @@ int unsetenv (const char *);
 void *aligned_alloc(size_t, size_t);
 #endif
 
+#if defined (_WIN32) && defined(__MINGW32__)
+#define aligned_free(ptr)  __mingw_aligned_free(ptr)
+#elif defined (_WIN32) && defined(_MSC_VER)
+#define aligned_free(ptr)  _aligned_free(ptr)
+#else
+#define aligned_free(ptr)  free(ptr)
+#endif
+
 #if defined(__native_client__) && defined(__cplusplus)
 # define HAVE_USELOCALE
 #endif
index 4bc2e91..6c20c13 100644 (file)
@@ -49,7 +49,7 @@ int CopyInitCache(copy_cache_t *cache, unsigned width)
 void CopyCleanCache(copy_cache_t *cache)
 {
 #ifdef CAN_COMPILE_SSE2
-    free(cache->buffer);
+    aligned_free(cache->buffer);
     cache->buffer = NULL;
     cache->size   = 0;
 #else
index 317c604..8ebb95d 100644 (file)
@@ -168,7 +168,7 @@ static void Close(vlc_object_t *object)
 
     var_DelCallback(filter, CFG_PREFIX "radius",   Callback, NULL);
     var_DelCallback(filter, CFG_PREFIX "strength", Callback, NULL);
-    free(sys->cfg.buf);
+    aligned_free(sys->cfg.buf);
     vlc_mutex_destroy(&sys->lock);
     free(sys);
 }
index 348a681..880c9e4 100644 (file)
@@ -951,7 +951,7 @@ EvasImageBuffersFree( vout_display_t *vd )
     vout_display_sys_t *sys = vd->sys;
 
     for( unsigned int i = 0; i < sys->i_nb_buffers; i++ )
-        free( sys->p_buffers[i].p[0] );
+        aligned_free( sys->p_buffers[i].p[0] );
     free( sys->p_buffers );
     sys->p_buffers = NULL;
     sys->i_nb_buffers = 0;
index 3bac926..7c170f0 100644 (file)
@@ -110,7 +110,7 @@ static void picture_DestroyFromResource( picture_t *p_picture )
  */
 static void picture_Destroy( picture_t *p_picture )
 {
-    free( p_picture->p[0].p_pixels );
+    aligned_free( p_picture->p[0].p_pixels );
     free( p_picture );
 }
 
index 0c5ea39..17bf3b7 100644 (file)
@@ -58,7 +58,7 @@ static void picture_pool_Destroy(picture_pool_t *pool)
 
     vlc_cond_destroy(&pool->wait);
     vlc_mutex_destroy(&pool->lock);
-    free(pool);
+    aligned_free(pool);
 }
 
 void picture_pool_Release(picture_pool_t *pool)