[MPlayer-dev-eng] [PATCH] Remove all usage of memalign.

Reimar Döffinger Reimar.Doeffinger at gmx.de
Thu Jun 11 01:35:51 EEST 2020


Completely switch to av_malloc instead.
The fallback for memalign has been plain malloc,
which meant crashes on e.g. Win32 where malloc
is not sufficiently aligned.
---
 configure          |  4 ----
 libmpdemux/video.c | 10 +++++-----
 loader/win32.c     |  4 ++--
 sub/sub.c          | 12 ++++++------
 4 files changed, 13 insertions(+), 17 deletions(-)

diff --git a/configure b/configure
index 12d119b5d..d21df0ff7 100755
--- a/configure
+++ b/configure
@@ -3988,8 +3988,6 @@ if test "$_memalign" = yes ; then
   def_memalign='#define HAVE_MEMALIGN 1'
 else
   def_memalign='#define HAVE_MEMALIGN 0'
-  def_map_memalign='#define memalign(a, b) malloc(b)'
-  darwin || def_memalign_hack='#define CONFIG_MEMALIGN_HACK 1'
 fi
 echores "$_memalign"
 
@@ -9008,7 +9006,6 @@ $def_glob
 $def_gmtime_r
 $def_langinfo
 $def_localtime_r
-$def_map_memalign
 $def_memalign
 $def_nanosleep
 $def_posix_select
@@ -9036,7 +9033,6 @@ $def_kstat
 $def_macosx_bundle
 $def_macosx_finder
 $def_maemo
-$def_memalign_hack
 $def_path_max_check
 $def_priority
 $def_quicktime
diff --git a/libmpdemux/video.c b/libmpdemux/video.c
index 80e6023ae..6b0927d73 100644
--- a/libmpdemux/video.c
+++ b/libmpdemux/video.c
@@ -134,7 +134,7 @@ switch(video_codec){
    }
    mp_msg(MSGT_DECVIDEO,MSGL_V,"OK!\n");
    if(!videobuffer) {
-     videobuffer = memalign(8, VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
+     videobuffer = av_malloc(VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
      if (videobuffer) memset(videobuffer+VIDEOBUFFER_SIZE, 0, MP_INPUT_BUFFER_PADDING_SIZE);
      else {
        mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_ShMemAllocFail);
@@ -229,7 +229,7 @@ switch(video_codec){
    }
    mp_msg(MSGT_DECVIDEO,MSGL_V,"OK!\n");
    if(!videobuffer) {
-     videobuffer = memalign(8, VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
+     videobuffer = av_malloc(VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
      if (videobuffer) memset(videobuffer+VIDEOBUFFER_SIZE, 0, MP_INPUT_BUFFER_PADDING_SIZE);
      else {
        mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_ShMemAllocFail);
@@ -275,7 +275,7 @@ switch(video_codec){
  case VIDEO_HEVC: {
    videobuf_len=0; videobuf_code_len=0;
    if(!videobuffer) {
-     videobuffer = memalign(8, VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
+     videobuffer = av_malloc(VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
      if (videobuffer) memset(videobuffer+VIDEOBUFFER_SIZE, 0, MP_INPUT_BUFFER_PADDING_SIZE);
      else {
        mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_ShMemAllocFail);
@@ -306,7 +306,7 @@ mpeg_header_parser:
    mp_msg(MSGT_DECVIDEO,MSGL_V,"OK!\n");
    // ========= Read & process sequence header & extension ============
    if(!videobuffer) {
-     videobuffer = memalign(8, VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
+     videobuffer = av_malloc(VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
      if (videobuffer) memset(videobuffer+VIDEOBUFFER_SIZE, 0, MP_INPUT_BUFFER_PADDING_SIZE);
      else {
        mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_ShMemAllocFail);
@@ -374,7 +374,7 @@ mpeg_header_parser:
    }
    mp_msg(MSGT_DECVIDEO,MSGL_INFO,"found\n");
    if(!videobuffer) {
-     videobuffer = memalign(8, VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
+     videobuffer = av_malloc(VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
      if (videobuffer) memset(videobuffer+VIDEOBUFFER_SIZE, 0, MP_INPUT_BUFFER_PADDING_SIZE);
      else {
        mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_ShMemAllocFail);
diff --git a/loader/win32.c b/loader/win32.c
index bbd3fae42..f4cca1b46 100644
--- a/loader/win32.c
+++ b/loader/win32.c
@@ -351,7 +351,7 @@ void* mreq_private(int size, int to_zero, int type);
 void* mreq_private(int size, int to_zero, int type)
 {
     int nsize = size + sizeof(alloc_header);
-    alloc_header* header = memalign(16, nsize);
+    alloc_header* header = av_malloc(nsize);
     if (!header)
         return 0;
     if (to_zero)
@@ -436,7 +436,7 @@ static int my_release(void* memory)
 	return 0;
 #endif
     //memset(header + 1, 0xcc, header->size);
-    free(header);
+    av_free(header);
     return 0;
 }
 #endif
diff --git a/sub/sub.c b/sub/sub.c
index 0d285e134..142242179 100644
--- a/sub/sub.c
+++ b/sub/sub.c
@@ -156,10 +156,10 @@ static void alloc_buf(mp_osd_obj_t* obj)
     len = obj->stride*(obj->bbox.y2-obj->bbox.y1);
     if (obj->allocated<len) {
 	obj->allocated = len;
-	free(obj->bitmap_buffer);
-	free(obj->alpha_buffer);
-	obj->bitmap_buffer = memalign(16, len);
-	obj->alpha_buffer  = memalign(16, len);
+	av_freep(&obj->bitmap_buffer);
+	av_freep(&obj->alpha_buffer);
+	obj->bitmap_buffer = av_malloc(len);
+	obj->alpha_buffer  = av_malloc(len);
     }
     memset(obj->bitmap_buffer, sub_bg_color, len);
     memset(obj->alpha_buffer, sub_bg_alpha, len);
@@ -1101,8 +1101,8 @@ void free_osd_list(void){
     mp_osd_obj_t* obj=vo_osd_list;
     while(obj){
 	mp_osd_obj_t* next=obj->next;
-	free(obj->alpha_buffer);
-	free(obj->bitmap_buffer);
+	av_freep(&obj->alpha_buffer);
+	av_freep(&obj->bitmap_buffer);
 	free(obj);
 	obj=next;
     }
-- 
2.27.0



More information about the MPlayer-dev-eng mailing list