[Libav-user] Basic problem : memory leak when playing several movies

Fulbert Boussaton 42 at flubb.net
Thu Sep 12 16:08:01 CEST 2013


I investigated further and found I made a basic error : the releasing code was not called as it should !

So, the code was correct (bar the avpicture_free call) and doesn't leak at all.

Sorry for the noise...


Fulbert.


On Sep 12, 2013, at 14:46, Fulbert <42 at flubb.net> wrote:

> Hi everyone,
> 
> I use FFMpeg on iOS/armv7 (I just cloned the repository yesterday) and even though I easily managed to make a basic video player (thanks to all the devs by the way, the project is really a technical achievement !), I still have a frustrating memory leak problem.
> 
> Short version : some memory is not released each time I play (switch to) a new movie in the same run. The amount of leaking memory depends on the movie, the order is 500KB-5MB.
> 
> In order to better explain the situation, here are the operations I execute to open a new movie (The code is slightly modified to keep only the relevant calls) :
> 
> AVFormatContext*	Ctx;
> avformat_open_input(&Ctx, <...>, NULL, &Options);
> avformat_find_stream_info(Ctx, NULL);
> AVCodecContext* VCodecCtx = Ctx->streams[0]->codec;
> AVCodec* TargetVideoCodec = avcodec_find_decoder(VCodecCtx->codec_id);
> avcodec_open2(VCodecCtx, TargetVideoCodec, NULL);
> AVFrame* TargetFrame = avcodec_alloc_frame();
> AVFrame* TargetFrameRGB = avcodec_alloc_frame();
> int FrameSizeInBytes = avpicture_get_size(PIX_FMT_RGB24, VCodecCtx->width, VCodecCtx->height);
> uint8_t* FrameBuffer = (uint8_t*) av_malloc(FrameSizeInBytes);
> avpicture_fill((AVPicture*) TargetFrameRGB, FrameBuffer, PIX_FMT_RGB24, VCodecCtx->width, VCodecCtx->height);
> struct SwsContext* ScaleCtx = sws_getContext(VCodecCtx->width, VCodecCtx->height, VCodecCtx->pix_fmt, VCodecCtx->width, VCodecCtx->height, PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL);
> 
> And here are the functions I call to release all the previous structures :
> 
> sws_freeContext(ScaleCtx);
> avpicture_free((AVPicture*)TargetFrameRGB);
> av_free(FrameBuffer);
> avcodec_free_frame(&TargetFrame);
> avcodec_free_frame(&TargetFrameRGB);
> avcodec_close(VCodecCtx);
> avformat_close_input(&Ctx);
> 
> There's no AVPacket management, picture scaling or anything graphical here because I tried to present you the minimal pieces of code for which the problem occurs.
> 
> Obviously, I didn't release something I asked to be allocated so I'm sure I've forgot to call a avXXX_free_something but I can't find anything in the sources and I'm quite stuck.
> 
> Is there anybody who can see what the problem is ?
> 
> 
> Thanks.
> 
> Fulbert.
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user



More information about the Libav-user mailing list