changeset 27765:03bb6c3945ff

Use av_malloc/av_free for audio-related buffers to avoid crashes due to insufficient alignment on systems without memalign. http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/2008-October/058743.html
author reimar
date Sat, 18 Oct 2008 18:54:05 +0000
parents 7de310806281
children e49937996ec2
files libmpcodecs/ad_twin.c libmpcodecs/dec_audio.c
diffstat 2 files changed, 5 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/libmpcodecs/ad_twin.c	Sat Oct 18 16:07:47 2008 +0000
+++ b/libmpcodecs/ad_twin.c	Sat Oct 18 18:54:05 2008 +0000
@@ -138,7 +138,7 @@
     priv->framesize=TvqGetFrameSize();
     sh_audio->audio_in_minsize=priv->framesize*in_fmt->nChannels;
     sh_audio->a_in_buffer_size=4*sh_audio->audio_in_minsize;
-    sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size);
+    sh_audio->a_in_buffer=av_malloc(sh_audio->a_in_buffer_size);
     sh_audio->a_in_buffer_len=0;
 
 
--- a/libmpcodecs/dec_audio.c	Sat Oct 18 16:07:47 2008 +0000
+++ b/libmpcodecs/dec_audio.c	Sat Oct 18 18:54:05 2008 +0000
@@ -74,8 +74,7 @@
 	sh_audio->a_in_buffer_size = sh_audio->audio_in_minsize;
 	mp_msg(MSGT_DECAUDIO, MSGL_V, MSGTR_AllocatingBytesForInputBuffer,
 	       sh_audio->a_in_buffer_size);
-	sh_audio->a_in_buffer = memalign(16, sh_audio->a_in_buffer_size);
-	memset(sh_audio->a_in_buffer, 0, sh_audio->a_in_buffer_size);
+	sh_audio->a_in_buffer = av_mallocz(sh_audio->a_in_buffer_size);
 	sh_audio->a_in_buffer_len = 0;
     }
 
@@ -84,12 +83,11 @@
     mp_msg(MSGT_DECAUDIO, MSGL_V, MSGTR_AllocatingBytesForOutputBuffer,
 	   sh_audio->audio_out_minsize, MAX_OUTBURST, sh_audio->a_buffer_size);
 
-    sh_audio->a_buffer = memalign(16, sh_audio->a_buffer_size);
+    sh_audio->a_buffer = av_mallocz(sh_audio->a_buffer_size);
     if (!sh_audio->a_buffer) {
 	mp_msg(MSGT_DECAUDIO, MSGL_ERR, MSGTR_CantAllocAudioBuf);
 	return 0;
     }
-    memset(sh_audio->a_buffer, 0, sh_audio->a_buffer_size);
     sh_audio->a_buffer_len = 0;
 
     if (!sh_audio->ad_driver->init(sh_audio)) {
@@ -306,12 +304,8 @@
     free(sh_audio->a_out_buffer);
     sh_audio->a_out_buffer = NULL;
     sh_audio->a_out_buffer_size = 0;
-    if (sh_audio->a_buffer)
-	free(sh_audio->a_buffer);
-    sh_audio->a_buffer = NULL;
-    if (sh_audio->a_in_buffer)
-	free(sh_audio->a_in_buffer);
-    sh_audio->a_in_buffer = NULL;
+    av_freep(&sh_audio->a_buffer);
+    av_freep(&sh_audio->a_in_buffer);
 }