[FFmpeg-devel] [PATCH] fix memleak in h264_parser
Reimar Döffinger
Reimar.Doeffinger
Thu Apr 9 21:57:30 CEST 2009
Hello,
currently the H264 parser never frees the SPS and PPS it allocates.
Attached patch is one way to fix it.
-------------- next part --------------
Index: libavcodec/h264.c
===================================================================
--- libavcodec/h264.c (revision 18389)
+++ libavcodec/h264.c (working copy)
@@ -8083,10 +8083,8 @@
#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,7 +8096,15 @@
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);
// memset(h, 0, sizeof(H264Context));
Index: libavcodec/h264.h
===================================================================
--- libavcodec/h264.h (revision 18389)
+++ libavcodec/h264.h (working copy)
@@ -569,4 +569,9 @@
*/
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 */
Index: libavcodec/h264_parser.c
===================================================================
--- libavcodec/h264_parser.c (revision 18389)
+++ libavcodec/h264_parser.c (working copy)
@@ -306,6 +306,7 @@
ParseContext *pc = &h->s.parse_context;
av_free(pc->buffer);
+ ff_h264_free_context(h);
}
More information about the ffmpeg-devel
mailing list