[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


I update the source code from Dranger's tutorials (http://dranger.com/ffmpeg/)
Here is tutorials01
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
    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->linesize, 0, pCodecCtx->height,
                          pFrameRGB->data, pFrameRGB->linesize);

                // Save the frame to disk
                    SaveFrame(pFrameRGB, pCodecCtx->width, pCodecCtx->height,


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


More information about the Libav-user mailing list