[FFmpeg-devel] One memory leakage in AAC/AC3 parser

David LIU david.liu
Thu Jun 12 10:36:01 CEST 2008

Hi Ffmpeg developer,

I found there is one potential memory leakage in AAC/AC3 parser.

Here I have one stream (AVI stream which contains Divx and AC3) and use ffmpeg to demux and decode.

What I found is that:

1. ff_aac_ac3_parse() parse this audio stream. It will call ff_combine_frame() to combine the truncated stream to a complete frame.

2. In ff_combine_frame(), av_fast_realloc() will  re-allocate a new memory.

3. But there is no code to de-allocate this memory allocated by ff_combine_frame() if I call av_parser_close().

So what I did is to 
1. add ff_parse2_close() in ac3_parser.c like below:

AVCodecParser ac3_parser = {
    { CODEC_ID_AC3 },
    // NULL, // david comment

2. add ff_parse2_close() in parser.c like below:

void ff_parse2_close(AVCodecParserContext *s) // david added for ac3 and aac
  AACAC3ParseContext *pc2 = s->priv_data;
#undef printf
    printf("ff_parse_close pc2 0x%x \n", pc2);
	printf("ff_parse_close pc2->pc 0x%x \n", &(pc2->pc));
	printf("ff_parse1_close pc2->pc.buffer 0x%x\n", pc2->pc.buffer); //david
#define printf	

After this modification, the memory allocated by ff_combine_frame() will be sure to be freed. Do you think my modification is meaningful?

Best regards

David Liu

Home Video Division

Tina: 041-4607

More information about the ffmpeg-devel mailing list