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 @@
#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
}
......@@ -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
*****************************************************************************/
......
......@@ -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
......
......@@ -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
......
......@@ -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);
}
......
......@@ -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;
......
......@@ -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 );
}
......
......@@ -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)
......
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