GNOME Bugzilla – Bug 172961
valgrind gives a lot of errors on gst-ffmpeg elements
Last modified: 2006-10-07 11:17:42 UTC
I'm using as command: valgrind --tool=addrcheck gst-launch-0.8 videotestsrc ! video/x-raw-yuv,width=128,height=128,framerate=20.0 ! ffmpegcolorspace ! ffenc_mpeg4 ! fakesink I'm attaching output of this command.
Created attachment 39806 [details] output of standard gst-ffmpeg
I don't think that errors that have __GI___libc_freeres (set-freeres.c:49) in the call trace are important. __libc_freeres is called by valgrind and is not called in a normal program (check man valgrind). So we have a lot of errors inside libavcodec. I'm able to get rid of all of av_free errors adding: #undef HAVE_MEMALIGN #undef MEMALIGN_HACK to mem.c in libavcodec. This works fine in valgrind but gives every type of strange errors if i run gst-launch directly. I've tried to add: AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext)); av_free (avctx); to _get_caps function in ffenc and valgrind gives error also in this line (the av_free one).. If i s/av_malloc/malloc and s/av_free/free it works fine! So i was thinking in a problem with valgrind and memalign but a simple: int main (int argc, char **argv) { void *p; p = memalign (16, 10); free (p); return 0; } works fine.. So i've added a: void *p; p = memalign (16, 10); free (p); to ffenc _get_caps function and... it gives error!! So.. is it a build issue? but: I've tried adding to _get_caps: void *p; posix_memalign (&p, 16, 10); free (p); and this works fine.. any idea? and sorry for the longest comment in the world :)
I've changed in mem.c ptr = memalign(16,size); with posix_memalign (&ptr, 16, size); and valgrind outputs is clear.. ffmpeg elements seem to work fine.. I'm attaching valgrind output
Created attachment 39808 [details] gst-ffmpeg with posix_memalign
Alternatively, we can do what the comment in mem.c says: /** * Memory allocation of size byte with alignment suitable for all * memory accesses (including vectors if available on the * CPU). av_malloc(0) must return a non NULL pointer. */ Anyone wanna write a patch that makes it use glib's g_{{re,m}alloc,free}? May give unwanted results otherwise in the SSE2 code, because it requires alignment. I'm ok with the posix_memalign patch to ffmpeg.
I've already tried using g_malloc instead of av_malloc but it gives a lot of problem(segfault) with sse2 code (as there's written on the mem.c comment). I've tried on a P4 and a Celeron with sse2 support.
OK, then posix_memalign() it is. Man memalign tells me it is the right decision...
Fixed.
few questions: 1- which valgrind version is that broken? 2- memalign is used instead of posix_memalign since it is known to work where it is implemented and where it isn't (darwin/freebsd) malloc provides correctly aligned buffers I'd revert the change and update valgrind and/or check with valgrind authors what's going on.