Skip to content

Commit c3a3afd

Browse files
robUx4tguillem
authored andcommitted
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 <[email protected]>
1 parent c95d5fb commit c3a3afd

File tree

8 files changed

+24
-24
lines changed

8 files changed

+24
-24
lines changed

compat/aligned_alloc.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <assert.h>
2626
#include <stdlib.h>
2727
#include <errno.h>
28-
#if !defined (HAVE_POSIX_MEMALIGN) && !defined (_WIN32)
28+
#if !defined (HAVE_POSIX_MEMALIGN)
2929
# include <malloc.h>
3030
#endif
3131

@@ -52,14 +52,16 @@ void *aligned_alloc(size_t align, size_t size)
5252
}
5353
return ptr;
5454

55-
#elif !defined (_WIN32)
56-
57-
return memalign(align, size);
58-
55+
#elif defined(HAVE_MEMALIGN)
56+
return memalign(align, size);
57+
#elif defined (_WIN32) && defined(__MINGW32__)
58+
return __mingw_aligned_malloc(size, align);
59+
#elif defined (_WIN32) && defined(_MSC_VER)
60+
return _aligned_malloc(size, align);
5961
#else
60-
61-
if (size > 0)
62-
errno = ENOMEM;
63-
return NULL;
62+
#warning unsupported aligned allocation!
63+
if (size > 0)
64+
errno = ENOMEM;
65+
return NULL;
6466
#endif
6567
}

include/vlc_common.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -845,16 +845,6 @@ VLC_API bool vlc_ureduce( unsigned *, unsigned *, uint64_t, uint64_t, uint64_t )
845845
#define container_of(ptr, type, member) \
846846
((type *)(((char *)(ptr)) - offsetof(type, member)))
847847

848-
/* Aligned memory allocator */
849-
850-
#ifdef __MINGW32__
851-
# define vlc_memalign(align, size) (__mingw_aligned_malloc(size, align))
852-
#elif defined(_MSC_VER)
853-
# define vlc_memalign(align, size) (_aligned_malloc(size, align))
854-
#else
855-
# define vlc_memalign(align, size) aligned_alloc(align, size)
856-
#endif
857-
858848
/*****************************************************************************
859849
* I18n stuff
860850
*****************************************************************************/

include/vlc_fixups.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,14 @@ int unsetenv (const char *);
306306
void *aligned_alloc(size_t, size_t);
307307
#endif
308308

309+
#if defined (_WIN32) && defined(__MINGW32__)
310+
#define aligned_free(ptr) __mingw_aligned_free(ptr)
311+
#elif defined (_WIN32) && defined(_MSC_VER)
312+
#define aligned_free(ptr) _aligned_free(ptr)
313+
#else
314+
#define aligned_free(ptr) free(ptr)
315+
#endif
316+
309317
#if defined(__native_client__) && defined(__cplusplus)
310318
# define HAVE_USELOCALE
311319
#endif

modules/video_chroma/copy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ int CopyInitCache(copy_cache_t *cache, unsigned width)
4949
void CopyCleanCache(copy_cache_t *cache)
5050
{
5151
#ifdef CAN_COMPILE_SSE2
52-
free(cache->buffer);
52+
aligned_free(cache->buffer);
5353
cache->buffer = NULL;
5454
cache->size = 0;
5555
#else

modules/video_filter/gradfun.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ static void Close(vlc_object_t *object)
168168

169169
var_DelCallback(filter, CFG_PREFIX "radius", Callback, NULL);
170170
var_DelCallback(filter, CFG_PREFIX "strength", Callback, NULL);
171-
free(sys->cfg.buf);
171+
aligned_free(sys->cfg.buf);
172172
vlc_mutex_destroy(&sys->lock);
173173
free(sys);
174174
}

modules/video_output/evas.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ EvasImageBuffersFree( vout_display_t *vd )
951951
vout_display_sys_t *sys = vd->sys;
952952

953953
for( unsigned int i = 0; i < sys->i_nb_buffers; i++ )
954-
free( sys->p_buffers[i].p[0] );
954+
aligned_free( sys->p_buffers[i].p[0] );
955955
free( sys->p_buffers );
956956
sys->p_buffers = NULL;
957957
sys->i_nb_buffers = 0;

src/misc/picture.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static void picture_DestroyFromResource( picture_t *p_picture )
110110
*/
111111
static void picture_Destroy( picture_t *p_picture )
112112
{
113-
free( p_picture->p[0].p_pixels );
113+
aligned_free( p_picture->p[0].p_pixels );
114114
free( p_picture );
115115
}
116116

src/misc/picture_pool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static void picture_pool_Destroy(picture_pool_t *pool)
5858

5959
vlc_cond_destroy(&pool->wait);
6060
vlc_mutex_destroy(&pool->lock);
61-
free(pool);
61+
aligned_free(pool);
6262
}
6363

6464
void picture_pool_Release(picture_pool_t *pool)

0 commit comments

Comments
 (0)