[Libav-user] [lav-user] Memory leaks in Mac OSX Lion

Quy Pham Sy phamsyquybk at gmail.com
Wed Oct 17 02:06:25 CEST 2012


Hi,

I update the source code from Dranger's tutorials (http://dranger.com/ffmpeg/)
Here is tutorials01
(https://github.com/phamquy/FFmpeg-tutorial-samples/blob/master/tutorial01.c),
Everything works fine, except there is a huge memory leak detected by
Mac's Instrument.

Here is the part i think is the suspected code, which i found that the
leak is gone if i commented out it

--------

// Read frames and save first five frames to disk
    i=0;
    while(av_read_frame(pFormatCtx, &packet)>=0) {
        if(packet.stream_index==videoStreamIdx) {
            avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet);

            if(frameFinished) {
                static struct SwsContext *img_convert_ctx;
                int w = pCodecCtx->width;
                int h = pCodecCtx->height;
                img_convert_ctx = sws_getContext(w, h, pCodecCtx->pix_fmt,
                                                 w, h, PIX_FMT_RGB24,
                                                 SWS_BICUBIC, NULL, NULL, NULL);

                sws_scale(img_convert_ctx, (const uint8_t * const
*)pFrame->data,
                          pFrame->linesize, 0, pCodecCtx->height,
                          pFrameRGB->data, pFrameRGB->linesize);

                // Save the frame to disk
                if(++i<=5)
                    SaveFrame(pFrameRGB, pCodecCtx->width, pCodecCtx->height,
                              i);
            }
        }
        av_free_packet(&packet);
    }

-------

What is wrong with these code that might cause the leak?

Thanks,
Jack


More information about the Libav-user mailing list