# HG changeset patch # User heydowns # Date 1201554758 0 # Node ID 52ccab2531bd971d3650d3005083f5b4c31368be # Parent 3e13247560d4577f0b520d143af623e89f5e6ef3 Fix memory leak in h264 decoder. allocated_edge_emu_buffer was being allocated in both mpegvideo and h264 decoder. Fixed by allowing all (master and duplicate) contexts to fully initialize in MPV_frame_start and copying these into H264Contexts. Mailing list discussion: [FFmpeg-devel] Memory leak in h264 Tue, 22 Jan 2008 15:22:55 diff -r 3e13247560d4 -r 52ccab2531bd h264.c --- a/h264.c Sun Jan 27 23:28:56 2008 +0000 +++ b/h264.c Mon Jan 28 21:12:38 2008 +0000 @@ -1951,7 +1951,6 @@ av_freep(&hx->top_borders[1]); av_freep(&hx->top_borders[0]); av_freep(&hx->s.obmc_scratchpad); - av_freep(&hx->s.allocated_edge_emu_buffer); } } @@ -2096,10 +2095,6 @@ CHECKED_ALLOCZ(h->top_borders[0], h->s.mb_width * (16+8+8) * sizeof(uint8_t)) CHECKED_ALLOCZ(h->top_borders[1], h->s.mb_width * (16+8+8) * sizeof(uint8_t)) - // 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; return 0; fail: return -1; // free_tables will clean up for us @@ -3907,7 +3902,7 @@ for(i = 1; i < s->avctx->thread_count; i++) { H264Context *c; c = h->thread_context[i] = av_malloc(sizeof(H264Context)); - memcpy(c, h, sizeof(MpegEncContext)); + memcpy(c, h->s.thread_context[i], sizeof(MpegEncContext)); memset(&c->s + 1, 0, sizeof(H264Context) - sizeof(MpegEncContext)); c->sps = h->sps; c->pps = h->pps; diff -r 3e13247560d4 -r 52ccab2531bd mpegvideo.c --- a/mpegvideo.c Sun Jan 27 23:28:56 2008 +0000 +++ b/mpegvideo.c Mon Jan 28 21:12:38 2008 +0000 @@ -587,9 +587,7 @@ s->context_initialized = 1; s->thread_context[0]= s; - /* h264 does thread context setup itself, but it needs context[0] - * to be fully initialized for the error resilience code */ - threads = s->codec_id == CODEC_ID_H264 ? 1 : s->avctx->thread_count; + threads = s->avctx->thread_count; for(i=1; ithread_context[i]= av_malloc(sizeof(MpegEncContext));