a sample file of H264 media fileffmpeg Memory leak when playing H264 media files When playing H264 media files I find there are some memory leak. 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! 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; ithread_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; ¡­¡­ }