Gstreamer & GLib memory management/profiling

Tim Müller tim at centricular.com
Fri Oct 31 14:06:17 PDT 2014


On Fri, 2014-10-31 at 21:51 +0100, Sergei Vorobyov wrote:

> Since GLib's memory profiling fails and there was a lot of Valgrind
> propaganda around, I gave it a try with: (snip)

> Therefore: I decided to perform an easy experiment with an obvious
> test leak:
> 
> 
>     gchar *leak;
>     for (gint i = 1; ; i++) {
>         // my main loop code here
>         leak = g_strdup_printf ("iteration %d", i);
>         g_printerr ("!!! LEAK: %s\n", leak);
>     }
> 
> 
> Obviously, Valgrind does not catch this trivial case (leak is never
> freed and non-recoverable):
> 
> 
> fl at nuc5:~/bin$ valgrind --leak-check=yes --leak-check=full
> --show-leak-kinds=all ./mp-v01.020 >../var/z3.txt
> ==8677== Memcheck, a memory error detector
> ==8677== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et
> al.
> ==8677== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for
> copyright info
> ==8677== Command: ./mp-v01.020
> ==8677== 
> !!! LEAK: iteration 1
> !!! LEAK: iteration 2
> !!! LEAK: iteration 3
> !!! LEAK: iteration 4
> !!! LEAK: iteration 5
> !!! LEAK: iteration 6
> !!! LEAK: iteration 7
> !!! LEAK: iteration 8
> ...
> 
> 
> I don't buy it...

Leaks will only shown when the program exits or you terminate it with
Control-C. And it will generally show this kind of leak just fine:

!!! LEAK: iteration 9682
!!! LEAK: iteration 9683
^C==26170== 
==26170== HEAP SUMMARY:
==26170==     in use at exit: 144,266 bytes in 9,690 blocks
==26170==   total heap usage: 77,478 allocs, 67,788 frees, 321,951,609
bytes allocated
==26170== 
==26170== 144,138 bytes in 9,683 blocks are definitely lost in loss
record 8 of 8
==26170==    at 0x4C28C20: malloc (vg_replace_malloc.c:296)
==26170==    by 0x5239BAF: __vasprintf_chk (vasprintf_chk.c:80)
==26170==    by 0x4EC247B: g_vasprintf
(in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4200.0)
==26170==    by 0x4E9D30C: g_strdup_vprintf
(in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4200.0)
==26170==    by 0x4E9D3C8: g_strdup_printf
(in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4200.0)
==26170==    by 0x4006EF: main (in /home/tpm/leak)
==26170== 
==26170== LEAK SUMMARY:
==26170==    definitely lost: 144,138 bytes in 9,683 blocks
==26170==    indirectly lost: 0 bytes in 0 blocks
==26170==      possibly lost: 0 bytes in 0 blocks
==26170==    still reachable: 128 bytes in 7 blocks
==26170==         suppressed: 0 bytes in 0 blocks
==26170== Reachable blocks (those to which a pointer was found) are not
shown.
==26170== To see them, rerun with: --leak-check=full
--show-leak-kinds=all
==26170== 
==26170== For counts of detected and suppressed errors, rerun with: -v
==26170== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

 Cheers
  -Tim

-- 
Tim Müller, Centricular Ltd - http://www.centricular.com



More information about the gstreamer-devel mailing list