In C, seg faults don't necessarily happen right where the problem is. Once the heap is corrupted, it could seg fault at some arbitrary point in the future. I've had similar problems, and I learned the hard way that the codecs own the frames/packets they give you. At one point I was decoding one frame, then closing the decoder codec & context, then doing other stuff with the frame. But closing the context freed the frame, so my program blew up. (It was actually dying down in some STL string resizing operation, which was absolutely no help in tracking down the problem.) This may not help... but in general, make sure you know what memory the library "owns" and will free for you, and what is your responsibility to free. You may not need to free what you think you do.

Andy

On 10/12/2010 10:55 PM, Michael Edenfield wrote:
I'm having some issues trying to clean up the memory allocations from using
libavformat and libavcodec, but I'm getting seemingly arbitrary segfaults when
doing so.  In particular, I cannot call avcodec_close, or
av_close_input_stream, without generating a segfault.

The locations where these segfaults appear to be happening don't make much
sense to me.  For avcodec_close, it claims to be faulting after this call
chain:

(I'm using static libav* libraries, linked into a dynamic JNI library, running
on my Android phone, so the debugging information is limited to running the
stack trace addresses through addr2line:)

#00  pc 00526724  av_freep /home/kutulu/workspace/ffmpeg/libavutil/mem.c:153
#01  pc 003e6304  avcodec_default_free_buffers
/home/kutulu/workspace/ffmpeg/libavcodec/utils.c:989
#02  pc 003e6c4c  avcodec_close
/home/kutulu/workspace/ffmpeg/libavcodec/utils.c:729

According to this, the segfault is happening here:

for(j=0; j<4; j++){
   av_freep(&buf->base[j]);  //<--- here
   buf->data[j]= NULL;
}

If I skip avcodec_close and just call av_close_input_stream, the stack trace
gives me:

#00  pc 0001066a  /system/lib/libc.so
#01  pc 0000afae  /system/lib/libc.so
#02  pc 00328aa4  av_parser_close
/home/kutulu/workspace/ffmpeg/libavcodec/parser.c:238
#03  pc 000beafc  av_close_input_stream
/home/kutulu/workspace/ffmpeg/libavformat/utils.c:2452

which is here (though I have also seen the segfault on the previous line, so
the addresses might be off a bit):

if (s->parser->parser_close)
     s->parser->parser_close(s);
av_free(s->priv_data); //<--- here
av_free(s);

I can't see why any of these things wouldn't be safe to free; I'm not doing
anything unusual with the contexts once I have them besides pass them to
av_read_frame and avcodec_decode_audio3.

Can anyone point me in the right direction?

--Mike
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user



_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to