[FFmpeg-devel] [PATCH] remove memory leak from tools/pktdumper.c

Zdenek Kabelac zdenek.kabelac
Thu Apr 30 11:44:49 CEST 2009


Hi

This small patch should adapt probably not often used
tools/pktdumper.c application to use newer packet reading API.
(So machines with small memory should be able to dump even very large streams)

It should fix these valgrind errors:

==4997== 21,528 bytes in 1 blocks are indirectly lost in loss record 1 of 4
==4997==    at 0x4C2576F: realloc (vg_replace_malloc.c:429)
==4997==    by 0x483138: av_fast_realloc (utils.c:76)
==4997==    by 0x40778C: av_add_index_entry.clone.4 (utils.c:1172)
==4997==    by 0x40ABFC: av_read_frame_internal (utils.c:931)
==4997==    by 0x4039AB: main (pktdumper.c:100)
==4997==
==4997==
==4997== 36,648 bytes in 7 blocks are indirectly lost in loss record 2 of 4
==4997==    at 0x4C23260: memalign (vg_replace_malloc.c:460)
==4997==    by 0x4C23317: posix_memalign (vg_replace_malloc.c:569)
==4997==    by 0x8BECA7: av_malloc (mem.c:66)
==4997==    by 0x40D58C: url_open_protocol (avio.c:76)
==4997==    by 0x40D748: url_open (avio.c:136)
==4997==    by 0x40EB00: url_fopen (aviobuf.c:603)
==4997==    by 0x409108: av_open_input_file (utils.c:449)
==4997==    by 0x40383F: main (pktdumper.c:86)
==4997==
==4997==
==4997== 125,256 (67,080 direct, 58,176 indirect) bytes in 130 blocks
are definitely lost in loss record 3 of 4
==4997==    at 0x4C23260: memalign (vg_replace_malloc.c:460)
==4997==    by 0x4C23317: posix_memalign (vg_replace_malloc.c:569)
==4997==    by 0x8BECA7: av_malloc (mem.c:66)
==4997==    by 0x47A227: avformat_alloc_context (options.c:80)
==4997==    by 0x4072A4: av_open_input_stream (utils.c:364)
==4997==    by 0x409294: av_open_input_file (utils.c:489)
==4997==    by 0x40383F: main (pktdumper.c:86)
==4997==


--------

Index: tools/pktdumper.c
===================================================================
--- tools/pktdumper.c   (revision 18717)
+++ tools/pktdumper.c   (working copy)
@@ -95,8 +95,6 @@
         return 1;
     }

-    av_init_packet(&pkt);
-
     while ((err = av_read_frame(fctx, &pkt)) >= 0) {
         int fd;
         snprintf(pktfilename, PATH_MAX-1, fntemplate, pktnum,
pkt.stream_index, pkt.pts, pkt.size, (pkt.flags &
PKT_FLAG_KEY)?'K':'_');
@@ -107,11 +105,14 @@
             write(fd, pkt.data, pkt.size);
             close(fd);
         }
+        av_free_packet(&pkt);
         pktnum++;
         if (maxpkts && (pktnum >= maxpkts))
             break;
     }

+    av_close_input_file(fctx);
+
     while (donotquit)
         sleep(60);



More information about the ffmpeg-devel mailing list