[Libav-user] Memory leaks with the function avformat_new_stream

mmendia mmendia at engineea.com
Wed Apr 24 09:39:02 CEST 2013



Hi all,

First of all, I am new to this mailing list, so hi everybody. I want to
make a program that mixes some packets of a couple of .ts files, the
program runs ok but valgrind detects some memory leaks and two of them
are quite big (23,288 bytes) and I do not know what to do.

I think i understand quite well what I am doing (use the right functions
at the right moment), and after having looked at it a lot I can not
figure out what is wrong.

This is Valgrinds ouptut:

==11908== Memcheck, a memory error detector
==11908== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==11908== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==11908== Command: ./CopyTsToTs hola-3.ts salida.ts
==11908==
[mpegts @ 0x4278060] max_analyze_duration 5000000 reached at 5013600
Input #0, mpegts, from 'hola-3.ts':
    Duration: 00:00:12.07, start: 25.688000, bitrate: 799 kb/s
    Program 1
      Metadata:
        service_name    : Service01
        service_provider: FFmpeg
      Stream #0:0[0x100]: Video: h264 (Constrained Baseline)
([27][0][0][0] / 0x001B), yuv420p, 640x360, 25 fps, 25 tbr, 90k tbn, 50 tbc
      Stream #0:1[0x101]: Audio: aac ([15][0][0][0] / 0x000F), 44100 Hz,
stereo, s16, 86 kb/s
Output #0, mpegts, to 'salida.ts':
      Stream #0:0: Video: h264 ([27][0][0][0] / 0x001B), yuv420p,
640x360, q=2-31, 90k tbn, 25 tbc
      Stream #0:1: Audio: aac ([15][0][0][0] / 0x000F), 44100 Hz, stereo,
86 kb/s
[mpegts @ 0x48348a0] muxrate VBR, pcr every 2 pkts, sdt every 200,
pat/pmt every 40 pkts
==11908==
==11908== HEAP SUMMARY:
==11908==     in use at exit: 46,622 bytes in 7 blocks
==11908==   total heap usage: 5,751 allocs, 5,744 frees, 9,552,334 bytes
allocated
==11908==
==11908== 8 bytes in 1 blocks are indirectly lost in loss record 1 of 7
==11908==    at 0x402BE68: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==11908==    by 0x402C007: realloc (in
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==11908==    by 0x86D3B07: av_dict_set (dict.c:82)
==11908==    by 0x81232CA: avformat_write_header (utils.c:3446)
==11908==    by 0x804AE75: CopyTsPacketByPacket (CopyTsToTs.c:258)
==11908==    by 0x804B2BC: main (CopyTsToTs.c:44)
==11908==
==11908== 8 bytes in 1 blocks are indirectly lost in loss record 2 of 7
==11908==    at 0x402A420: memalign (in
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==11908==    by 0x402A4DE: posix_memalign (in
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==11908==    by 0x86DADEF: av_strdup (mem.c:95)
==11908==    by 0x86D3AC6: av_dict_set (dict.c:92)
==11908==    by 0x81232CA: avformat_write_header (utils.c:3446)
==11908==    by 0x804AE75: CopyTsPacketByPacket (CopyTsToTs.c:258)
==11908==    by 0x804B2BC: main (CopyTsToTs.c:44)
==11908==
==11908== 8 bytes in 1 blocks are definitely lost in loss record 3 of 7
==11908==    at 0x402BF52: realloc (in
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==11908==    by 0x812594E: avformat_new_stream (utils.c:3147)
==11908==    by 0x804AA66: add_output_stream (CopyTsToTs.c:82)
==11908==    by 0x804AFAF: CopyTsPacketByPacket (CopyTsToTs.c:242)
==11908==    by 0x804B2BC: main (CopyTsToTs.c:44)
==11908==
==11908== 14 bytes in 1 blocks are indirectly lost in loss record 4 of 7
==11908==    at 0x402A420: memalign (in
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==11908==    by 0x402A4DE: posix_memalign (in
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==11908==    by 0x86DADEF: av_strdup (mem.c:95)
==11908==    by 0x86D3A35: av_dict_set (dict.c:102)
==11908==    by 0x81232CA: avformat_write_header (utils.c:3446)
==11908==    by 0x804AE75: CopyTsPacketByPacket (CopyTsToTs.c:258)
==11908==    by 0x804B2BC: main (CopyTsToTs.c:44)
==11908==
==11908== 38 (8 direct, 30 indirect) bytes in 1 blocks are definitely
lost in loss record 5 of 7
==11908==    at 0x402A420: memalign (in
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==11908==    by 0x402A4DE: posix_memalign (in
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==11908==    by 0x86DACAF: av_mallocz (mem.c:95)
==11908==    by 0x86D3ADB: av_dict_set (dict.c:70)
==11908==    by 0x81232CA: avformat_write_header (utils.c:3446)
==11908==    by 0x804AE75: CopyTsPacketByPacket (CopyTsToTs.c:258)
==11908==    by 0x804B2BC: main (CopyTsToTs.c:44)
==11908==
==11908== 23,288 bytes in 1 blocks are definitely lost in loss record 6 of 7
==11908==    at 0x402A420: memalign (in
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==11908==    by 0x402A4DE: posix_memalign (in
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==11908==    by 0x86DACAF: av_mallocz (mem.c:95)
==11908==    by 0x812597B: avformat_new_stream (utils.c:3155)
==11908==    by 0x804AA66: add_output_stream (CopyTsToTs.c:82)
==11908==    by 0x804ADD7: CopyTsPacketByPacket (CopyTsToTs.c:237)
==11908==    by 0x804B2BC: main (CopyTsToTs.c:44)
==11908==
==11908== 23,288 bytes in 1 blocks are definitely lost in loss record 7 of 7
==11908==    at 0x402A420: memalign (in
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==11908==    by 0x402A4DE: posix_memalign (in
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==11908==    by 0x86DACAF: av_mallocz (mem.c:95)
==11908==    by 0x812597B: avformat_new_stream (utils.c:3155)
==11908==    by 0x804AA66: add_output_stream (CopyTsToTs.c:82)
==11908==    by 0x804AFAF: CopyTsPacketByPacket (CopyTsToTs.c:242)
==11908==    by 0x804B2BC: main (CopyTsToTs.c:44)
==11908==
==11908== LEAK SUMMARY:
==11908==    definitely lost: 46,592 bytes in 4 blocks
==11908==    indirectly lost: 30 bytes in 3 blocks
==11908==      possibly lost: 0 bytes in 0 blocks
==11908==    still reachable: 0 bytes in 0 blocks
==11908==         suppressed: 0 bytes in 0 blocks
==11908==
==11908== For counts of detected and suppressed errors, rerun with: -v
==11908== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 0 from 0)

I attach a source code that just copyes a .ts file into other .ts file
packet by packet. The compilation, valgrind and mtrace instructions are
on it. I also attach a little .ts file.

It looks like it misses some reference...

Thank you in advance!

Miguel



-------------- next part --------------
A non-text attachment was scrubbed...
Name: CopyTsToTs.c
Type: text/x-csrc
Size: 10700 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20130424/d888598e/attachment.bin>


More information about the Libav-user mailing list