[Libav-user] Correct way to free AVFrame?

Udo Pokojski ffmpeg at upokojski.de
Mon Apr 5 14:40:36 EEST 2021


Hello,

In my program I initialize an AVFrame like this:

AVFrame *TestFrameRGB = NULL;
if (!TestFrameRGB)
    {
        TestFrameRGB=av_frame_alloc();
av_image_alloc(TestFrameRGB->data,TestFrameRGB->linesize,
pCodecCtx->width/scale,pCodecCtx->height/scale,
                     AV_PIX_FMT_RGB24,1);
    }


After using the AVFrame, I call these commands to free the allocated memory:

av_frame_unref(TestFrameRGB);
av_freep(&TestFrameRGB->data[0]);
av_frame_free(&TestFrameRGB);

The program works fine, but it consumes a lot of memory. A check with 
valgrind reports the memory allocated by av_image_alloc as definitely 
lost. I am using ffmpeg 4.2.4 on Ubuntu 20.04.
How can I free the allocated memory properly?

Thanks in advance,
Udo





More information about the Libav-user mailing list