[Libav-user] How can I free data buffers missed by avcodec_free_frame?

Czarnek, Matt mczarnek at objectvideo.com
Fri Mar 29 19:27:12 CET 2013

In the description for avcodec_free_frame, it states:

"Warning: this function does NOT free the data buffers themselves"

I have allocated my buffers as such:
int curAVFramesize = avpicture_get_size(PIX_FMT_YUV420P, ccontext->width,
uint8_t* curAVFramePicBuffer = (uint8_t*)(av_malloc(curAVFramesize));
AVFrame *curAVFrame=avcodec_alloc_frame();
avpicture_fill((AVPicture *)curAVFrame,curAVFramePicBuffer,
PIX_FMT_YUV420P,ccontext->width, ccontext->height);

I figured that the warning meant calling 'avpicture_free' was nessecary. So
I've been freeing it as:
avpicture_free((AVPicture *)curAVFrame);
avcodec_free_frame((AVFrame **)(&curAVFrame));

Usually my program doesn't complain but every once in a while, after
calling 'avpicture_free' but before 'avcodec_free_frame' it'll throw a heap
allocation error.

Here is the entire function: http://pastebin.com/jHecUySU

Is avpicture_free needed?  Any thoughts as to what might be happening?

Thank you!

Matt Czarnek, Software Engineer
Work Phone:  (760) 4-OBJVID
             aka:  (760) 462-5843


ObjectVideo Inc.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20130329/f703bdfd/attachment.html>

More information about the Libav-user mailing list