Commit c3a3afd3 authored by Steve Lhomme's avatar Steve Lhomme Committed by Thomas Guillem

core: add aligned_free to match the aligned_alloc used in the code

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's avatarThomas Guillem <thomas@gllm.fr>
parent c95d5fbe
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#if !defined (HAVE_POSIX_MEMALIGN) && !defined (_WIN32) #if !defined (HAVE_POSIX_MEMALIGN)
# include <malloc.h> # include <malloc.h>
#endif #endif
...@@ -52,14 +52,16 @@ void *aligned_alloc(size_t align, size_t size) ...@@ -52,14 +52,16 @@ void *aligned_alloc(size_t align, size_t size)
} }
return ptr; return ptr;
#elif !defined (_WIN32) #elif defined(HAVE_MEMALIGN)
return memalign(align, size);
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 #else
#warning unsupported aligned allocation!
if (size > 0) if (size > 0)
errno = ENOMEM; errno = ENOMEM;
return NULL; return NULL;
#endif #endif
} }
...@@ -845,16 +845,6 @@ VLC_API bool vlc_ureduce( unsigned *, unsigned *, uint64_t, uint64_t, uint64_t ) ...@@ -845,16 +845,6 @@ VLC_API bool vlc_ureduce( unsigned *, unsigned *, uint64_t, uint64_t, uint64_t )
#define container_of(ptr, type, member) \ #define container_of(ptr, type, member) \
((type *)(((char *)(ptr)) - offsetof(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 * I18n stuff
*****************************************************************************/ *****************************************************************************/
......
...@@ -306,6 +306,14 @@ int unsetenv (const char *); ...@@ -306,6 +306,14 @@ int unsetenv (const char *);
void *aligned_alloc(size_t, size_t); void *aligned_alloc(size_t, size_t);
#endif #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) #if defined(__native_client__) && defined(__cplusplus)
# define HAVE_USELOCALE # define HAVE_USELOCALE
#endif #endif
......
...@@ -49,7 +49,7 @@ int CopyInitCache(copy_cache_t *cache, unsigned width) ...@@ -49,7 +49,7 @@ int CopyInitCache(copy_cache_t *cache, unsigned width)
void CopyCleanCache(copy_cache_t *cache) void CopyCleanCache(copy_cache_t *cache)
{ {
#ifdef CAN_COMPILE_SSE2 #ifdef CAN_COMPILE_SSE2
free(cache->buffer); aligned_free(cache->buffer);
cache->buffer = NULL; cache->buffer = NULL;
cache->size = 0; cache->size = 0;
#else #else
......
...@@ -168,7 +168,7 @@ static void Close(vlc_object_t *object) ...@@ -168,7 +168,7 @@ static void Close(vlc_object_t *object)
var_DelCallback(filter, CFG_PREFIX "radius", Callback, NULL); var_DelCallback(filter, CFG_PREFIX "radius", Callback, NULL);
var_DelCallback(filter, CFG_PREFIX "strength", Callback, NULL); var_DelCallback(filter, CFG_PREFIX "strength", Callback, NULL);
free(sys->cfg.buf); aligned_free(sys->cfg.buf);
vlc_mutex_destroy(&sys->lock); vlc_mutex_destroy(&sys->lock);
free(sys); free(sys);
} }
......
...@@ -951,7 +951,7 @@ EvasImageBuffersFree( vout_display_t *vd ) ...@@ -951,7 +951,7 @@ EvasImageBuffersFree( vout_display_t *vd )
vout_display_sys_t *sys = vd->sys; vout_display_sys_t *sys = vd->sys;
for( unsigned int i = 0; i < sys->i_nb_buffers; i++ ) 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 ); free( sys->p_buffers );
sys->p_buffers = NULL; sys->p_buffers = NULL;
sys->i_nb_buffers = 0; sys->i_nb_buffers = 0;
......
...@@ -110,7 +110,7 @@ static void picture_DestroyFromResource( picture_t *p_picture ) ...@@ -110,7 +110,7 @@ static void picture_DestroyFromResource( picture_t *p_picture )
*/ */
static void picture_Destroy( 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 ); free( p_picture );
} }
......
...@@ -58,7 +58,7 @@ static void picture_pool_Destroy(picture_pool_t *pool) ...@@ -58,7 +58,7 @@ static void picture_pool_Destroy(picture_pool_t *pool)
vlc_cond_destroy(&pool->wait); vlc_cond_destroy(&pool->wait);
vlc_mutex_destroy(&pool->lock); vlc_mutex_destroy(&pool->lock);
free(pool); aligned_free(pool);
} }
void picture_pool_Release(picture_pool_t *pool) void picture_pool_Release(picture_pool_t *pool)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment