[FFmpeg-devel] [PATCH] fix memleak in packet corrupt dropping code
Chris Kennedy
bitbytebit at gmail.com
Mon Oct 17 17:33:13 CEST 2011
There is a memleak in the packet dropping method used when
packets are corrupt, this patch fixes it. Valgrind shows
it nice after this change, otherwise it leaks...
Thanks,
Chris
--
Chris Kennedy
ckennedy at groovy.org
-------------- next part --------------
==14418==
==14418== HEAP SUMMARY:
==14418== in use at exit: 144,139,212 bytes in 1,061 blocks
==14418== total heap usage: 161,919 allocs, 160,858 frees, 3,289,781,668 bytes allocated
==14418==
==14418== 272 bytes in 1 blocks are possibly lost in loss record 1 of 10
==14418== at 0x4C24B84: calloc (vg_replace_malloc.c:467)
==14418== by 0x4010D44: _dl_allocate_tls (in /lib64/ld-2.14.so)
==14418== by 0x5EB82F5: pthread_create@@GLIBC_2.2.5 (in /lib64/libpthread-2.14.so)
==14418== by 0x4C3D81: udp_open (udp.c:519)
==14418== by 0x448BA6: ffurl_connect (avio.c:128)
==14418== by 0x4492F7: ffurl_open (avio.c:253)
==14418== by 0x44DB6A: avio_open (aviobuf.c:942)
==14418== by 0x4CC340: avformat_open_input (utils.c:624)
==14418== by 0x43602A: start_demuxer (slicer.c:1347)
==14418== by 0x437101: main (slicer.c:501)
==14418==
==14418== 166,370 bytes in 4 blocks are definitely lost in loss record 2 of 10
==14418== at 0x4C26582: realloc (vg_replace_malloc.c:525)
==14418== by 0x4C7E9F: av_read_packet (utils.c:796)
==14418== by 0x4C8B06: read_frame_internal (utils.c:1219)
==14418== by 0x4CA5C0: avformat_find_stream_info (utils.c:2412)
==14418== by 0x436075: start_demuxer (slicer.c:1360)
==14418== by 0x437101: main (slicer.c:501)
==14418==
==14418== 204,816 bytes in 1 blocks are possibly lost in loss record 3 of 10
==14418== at 0x4C249B8: memalign (vg_replace_malloc.c:581)
==14418== by 0x4C24A67: posix_memalign (vg_replace_malloc.c:709)
==14418== by 0x93A61F: av_malloc (mem.c:90)
==14418== by 0x487D26: mpegts_push_data (mpegts.c:742)
==14418== by 0x4883CC: handle_packet (mpegts.c:1382)
==14418== by 0x488B28: handle_packets (mpegts.c:1473)
==14418== by 0x488B98: mpegts_read_packet (mpegts.c:1691)
==14418== by 0x4C7D2E: av_read_packet (utils.c:744)
==14418== by 0x4C8B06: read_frame_internal (utils.c:1219)
==14418== by 0x4C9336: av_read_frame (utils.c:1329)
==14418== by 0x437609: main (slicer.c:593)
==14418==
==14418== 204,816 bytes in 1 blocks are definitely lost in loss record 5 of 10
==14418== at 0x4C249B8: memalign (vg_replace_malloc.c:581)
==14418== by 0x4C24A67: posix_memalign (vg_replace_malloc.c:709)
==14418== by 0x93A61F: av_malloc (mem.c:90)
==14418== by 0x487C84: mpegts_push_data (mpegts.c:838)
==14418== by 0x4883CC: handle_packet (mpegts.c:1382)
==14418== by 0x488B28: handle_packets (mpegts.c:1473)
==14418== by 0x488B98: mpegts_read_packet (mpegts.c:1691)
==14418== by 0x4C7D2E: av_read_packet (utils.c:744)
==14418== by 0x4C8B06: read_frame_internal (utils.c:1219)
==14418== by 0x4C9336: av_read_frame (utils.c:1329)
==14418== by 0x437609: main (slicer.c:593)
==14418==
==14418== 1,228,896 bytes in 6 blocks are possibly lost in loss record 7 of 10
==14418== at 0x4C249B8: memalign (vg_replace_malloc.c:581)
==14418== by 0x4C24A67: posix_memalign (vg_replace_malloc.c:709)
==14418== by 0x93A61F: av_malloc (mem.c:90)
==14418== by 0x487D26: mpegts_push_data (mpegts.c:742)
==14418== by 0x4883CC: handle_packet (mpegts.c:1382)
==14418== by 0x488B28: handle_packets (mpegts.c:1473)
==14418== by 0x488B98: mpegts_read_packet (mpegts.c:1691)
==14418== by 0x4C7D2E: av_read_packet (utils.c:744)
==14418== by 0x4C8B06: read_frame_internal (utils.c:1219)
==14418== by 0x4CA5C0: avformat_find_stream_info (utils.c:2412)
==14418== by 0x436075: start_demuxer (slicer.c:1360)
==14418== by 0x437101: main (slicer.c:501)
==14418==
==14418== 6,349,296 bytes in 31 blocks are definitely lost in loss record 8 of 10
==14418== at 0x4C249B8: memalign (vg_replace_malloc.c:581)
==14418== by 0x4C24A67: posix_memalign (vg_replace_malloc.c:709)
==14418== by 0x93A61F: av_malloc (mem.c:90)
==14418== by 0x487C84: mpegts_push_data (mpegts.c:838)
==14418== by 0x4883CC: handle_packet (mpegts.c:1382)
==14418== by 0x488B28: handle_packets (mpegts.c:1473)
==14418== by 0x488B98: mpegts_read_packet (mpegts.c:1691)
==14418== by 0x4C7D2E: av_read_packet (utils.c:744)
==14418== by 0x4C8B06: read_frame_internal (utils.c:1219)
==14418== by 0x4CA5C0: avformat_find_stream_info (utils.c:2412)
==14418== by 0x436075: start_demuxer (slicer.c:1360)
==14418== by 0x437101: main (slicer.c:501)
==14418==
==14418== 26,311,920 (26,107,104 direct, 204,816 indirect) bytes in 169 blocks are definitely lost in loss record 9 of 10
==14418== at 0x4C249B8: memalign (vg_replace_malloc.c:581)
==14418== by 0x4C24A67: posix_memalign (vg_replace_malloc.c:709)
==14418== by 0x93A61F: av_malloc (mem.c:90)
==14418== by 0x487D26: mpegts_push_data (mpegts.c:742)
==14418== by 0x4883CC: handle_packet (mpegts.c:1382)
==14418== by 0x488B28: handle_packets (mpegts.c:1473)
==14418== by 0x488B98: mpegts_read_packet (mpegts.c:1691)
==14418== by 0x4C7D2E: av_read_packet (utils.c:744)
==14418== by 0x4C8B06: read_frame_internal (utils.c:1219)
==14418== by 0x4C9336: av_read_frame (utils.c:1329)
==14418== by 0x437609: main (slicer.c:593)
==14418==
==14418== 109,672,826 (108,853,562 direct, 819,264 indirect) bytes in 843 blocks are definitely lost in loss record 10 of 10
==14418== at 0x4C249B8: memalign (vg_replace_malloc.c:581)
==14418== by 0x4C24A67: posix_memalign (vg_replace_malloc.c:709)
==14418== by 0x93A61F: av_malloc (mem.c:90)
==14418== by 0x487D26: mpegts_push_data (mpegts.c:742)
==14418== by 0x4883CC: handle_packet (mpegts.c:1382)
==14418== by 0x488B28: handle_packets (mpegts.c:1473)
==14418== by 0x488B98: mpegts_read_packet (mpegts.c:1691)
==14418== by 0x4C7D2E: av_read_packet (utils.c:744)
==14418== by 0x4C8B06: read_frame_internal (utils.c:1219)
==14418== by 0x4CA5C0: avformat_find_stream_info (utils.c:2412)
==14418== by 0x436075: start_demuxer (slicer.c:1360)
==14418== by 0x437101: main (slicer.c:501)
==14418==
==14418== LEAK SUMMARY:
==14418== definitely lost: 141,681,148 bytes in 1,048 blocks
==14418== indirectly lost: 1,024,080 bytes in 5 blocks
==14418== possibly lost: 1,433,984 bytes in 8 blocks
==14418== still reachable: 0 bytes in 0 blocks
==14418== suppressed: 0 bytes in 0 blocks
==14418==
==14418== For counts of detected and suppressed errors, rerun with: -v
==14418== ERROR SUMMARY: 8 errors from 8 contexts (suppressed: 6 from 6)
-------------- next part --------------
diff --git a/libavformat/utils.c b/libavformat/utils.c
index c7eb93f..849dbce 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -756,6 +756,9 @@ int av_read_packet(AVFormatContext *s, AVPacket *pkt)
av_log(s, AV_LOG_WARNING,
"Dropped corrupted packet (stream = %d)\n",
pkt->stream_index);
+ if(!(s->flags & AVFMT_FLAG_KEEP_SIDE_DATA))
+ av_packet_merge_side_data(pkt);
+ av_free_packet(pkt);
continue;
}
More information about the ffmpeg-devel
mailing list