[FFmpeg-devel] ffmpeg Memory leak when playing H264 media files

linhui linhuiii
Thu Nov 29 04:17:24 CET 2007


Hi

I found that there are some memory leaks when playing H264 media files.

Here is detail.

 

Two files(h264.c and mpegvideo.c) are Involved with it. 
In function "decode_slice_header", MPV_common_init finally allocate memory
for s->allocated_edge_emu_buffer, and context_init also finally allocate
memory for s->allocated_edge_emu_buffer. From context we can judge that the
two s->allocated_edge_emu_buffer pointer are the same, so the memory
allocated by MPV_common_init leak when context_init allocate again. 
 
I'm not familiar with the whole code, I just find this problem by the
debugging of playing a H264 media file. Maybe someone can give a actual
reason about it and modify it. thanks!

I upload a sample file to MPlayer FTP: /MPlayer/incoming/H264File
 
static int decode_slice_header(H264Context *h, H264Context *h0) 
{ 
MpegEncContext * const s = &h->s; 
.. 
if (!s->context_initialized)  
{ 
if(h != h0) 
return -1;  
if (MPV_common_init(s) < 0) 
return -1; 
.. 
for(i = 0; i < s->avctx->thread_count; i++) 
if(context_init(h->thread_context[i]) < 0) 
return -1; 
.. 
} 
} 
 
int MPV_common_init(MpegEncContext *s) 
{ 
.. 
for(i=0; i<threads; i++) 
{ 
if(init_duplicate_context(s->thread_context[i], s) < 0) 
goto fail; 
} 
.. 
} 
 
static int init_duplicate_context(MpegEncContext *s, MpegEncContext *base) 
{ 
// edge emu needs blocksize + filter length - 1 (=17x17 for halfpel / 21x21
for h264) 
CHECKED_ALLOCZ(s->allocated_edge_emu_buffer, (s->width+64)*2*21*2); //(width
+ edge + align)*interlaced*MBsize*tolerance 
s->edge_emu_buffer= s->allocated_edge_emu_buffer + (s->width+64)*2*21; 
.. 
} 
 
static int context_init(H264Context *h)

{ 
MpegEncContext * const s = &h->s; 
// edge emu needs blocksize + filter length - 1 (=17x17 for halfpel / 21x21
for h264) 
CHECKED_ALLOCZ(s->allocated_edge_emu_buffer, 
(s->width+64)*2*21*2); //(width + edge + align)*interlaced*MBsize*tolerance 
s->edge_emu_buffer= s->allocated_edge_emu_buffer + (s->width+64)*2*21; 
.. 
} 

 





More information about the ffmpeg-devel mailing list