From 15861962a7a9e64fbe75f5cc0dc7d1c032db8dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reimar=20D=C3=B6ffinger?= Date: Fri, 10 Apr 2009 07:01:55 +0000 Subject: [PATCH] Add a ff_h264_free_context function and call it from the H.264 parser. This ensures that the parser will no longer leak memory for all SPS/PPS it encounters. Originally committed as revision 18406 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/h264.c | 12 +++++++++--- libavcodec/h264.h | 5 +++++ libavcodec/h264_parser.c | 1 + 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/libavcodec/h264.c b/libavcodec/h264.c index 1b5aeb2ceb..3eb1386a24 100644 --- a/libavcodec/h264.c +++ b/libavcodec/h264.c @@ -8083,10 +8083,8 @@ int main(void){ #endif /* TEST */ -static av_cold int decode_end(AVCodecContext *avctx) +av_cold ff_h264_free_context(H264Context *h) { - H264Context *h = avctx->priv_data; - MpegEncContext *s = &h->s; int i; av_freep(&h->rbsp_buffer[0]); @@ -8098,6 +8096,14 @@ static av_cold int decode_end(AVCodecContext *avctx) for(i = 0; i < MAX_PPS_COUNT; i++) av_freep(h->pps_buffers + i); +} + +static av_cold int decode_end(AVCodecContext *avctx) +{ + H264Context *h = avctx->priv_data; + MpegEncContext *s = &h->s; + + ff_h264_free_context(h); MPV_common_end(s); diff --git a/libavcodec/h264.h b/libavcodec/h264.h index fc9cef5d36..1f151af2cb 100644 --- a/libavcodec/h264.h +++ b/libavcodec/h264.h @@ -569,4 +569,9 @@ const uint8_t *ff_h264_decode_nal(H264Context *h, const uint8_t *src, int *dst_l */ int ff_h264_decode_rbsp_trailing(H264Context *h, const uint8_t *src); +/** + * frees any data that may have been allocated in the H264 context like SPS, PPS etc. + */ +av_cold ff_h264_free_context(H264Context *h); + #endif /* AVCODEC_H264_H */ diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c index 5f0c68c787..27f68d2380 100644 --- a/libavcodec/h264_parser.c +++ b/libavcodec/h264_parser.c @@ -306,6 +306,7 @@ static void close(AVCodecParserContext *s) ParseContext *pc = &h->s.parse_context; av_free(pc->buffer); + ff_h264_free_context(h); }