lists.zerezo.com



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[MPlayer-dev-eng] [PATCH] use av_malloc/av_free instead of malloc where missing memalign



Hi,

currently mplayer uses malloc instead of memalign when memalign is not
supported.

while often align(64) is used for perfomarnce reasons

align(16) is needed for sse code


The attached patch fixes it in dec_audio.c that avoids
crash while decoding an ogg vorbis

I've seen a similar patch in liba52 that checks for mingw+sse
but I think it's better to check for missing memalign

there are also other places to be fixed, but it's a bit
dangerous, since free() needs to be mapped to av_free __only__
if the buffer is allocated with av_malloc
(audio_dec -> a_buffer is ok to av_malloc/av_free,
a_in_buffer leads to stack corruptions, free-ed somewhere else?)

Regards

-- 
Gianluigi Tiesi <sherpya@xxxxxxxxxx>
EDP Project Leader
Netfarm S.r.l. - http://www.netfarm.it/
Free Software: http://oss.netfarm.it/
diff -NpuBr -Xexclude.txt main/libmpcodecs/dec_audio.c sherpya/libmpcodecs/dec_audio.c
--- main/libmpcodecs/dec_audio.c	2008-08-08 23:41:45.250000000 +0200
+++ sherpya/libmpcodecs/dec_audio.c	2008-10-12 01:15:10.312500000 +0200
@@ -84,7 +84,11 @@ static int init_audio_codec(sh_audio_t *
     mp_msg(MSGT_DECAUDIO, MSGL_V, MSGTR_AllocatingBytesForOutputBuffer,
 	   sh_audio->audio_out_minsize, MAX_OUTBURST, sh_audio->a_buffer_size);
 
+#ifdef HAVE_MEMALIGN
     sh_audio->a_buffer = memalign(16, sh_audio->a_buffer_size);
+#else
+    sh_audio->a_buffer = av_malloc(sh_audio->a_buffer_size);
+#endif
     if (!sh_audio->a_buffer) {
 	mp_msg(MSGT_DECAUDIO, MSGL_ERR, MSGTR_CantAllocAudioBuf);
 	return 0;
@@ -307,7 +311,11 @@ void uninit_audio(sh_audio_t *sh_audio)
     sh_audio->a_out_buffer = NULL;
     sh_audio->a_out_buffer_size = 0;
     if (sh_audio->a_buffer)
+#ifdef HAVE_MEMALIGN
 	free(sh_audio->a_buffer);
+#else
+    av_free(sh_audio->a_buffer);
+#endif
     sh_audio->a_buffer = NULL;
     if (sh_audio->a_in_buffer)
 	free(sh_audio->a_in_buffer);
_______________________________________________
MPlayer-dev-eng mailing list
MPlayer-dev-eng@xxxxxxxxxxxx
https://lists.mplayerhq.hu/mailman/listinfo/mplayer-dev-eng