I have no idea if your code is leaky but Perl runs its own memory pool and garbage collection and this causes valgrind to show lots of memory not free'ed at the end (as NERDVANA also said). There is a way to tell perl to free all memory at the end:

PERL_DESTRUCT_LEVEL If you want to run any of the tests yourself manually using e.g. valgr +ind, please note that by default perl does not explicitly clean up al +l the memory it has allocated (such as global memory arenas) but inst +ead lets the exit() of the whole program "take care" of such allocati +ons, also known as "global destruction of objects". There is a way to tell perl to do complete cleanup: set the environmen +t variable PERL_DESTRUCT_LEVEL to a non-zero value. The t/TEST wrappe +r does set this to 2, and this is what you need to do too, if you don +'t want to see the "global leaks": For example, for running under val +grind env PERL_DESTRUCT_LEVEL=2 valgrind ./perl -Ilib t/foo/bar.t
(see PERL_DESTRUCT_LEVEL)

There are lots of situations where valgrind complains in this way, e.g. with Qt or Xlib. "Valgrind suppression files" are used to tell valgrind what not to report for each of these situations. I am not sure if there is one for perl but perhaps Test::Valgrind can do this and without messing with those pesky command line switches.

Finally, I would create the simplest XS code which does nothing at all and pass that through valgrind in order to confirm that what I said indeed applies and how to suppress/filter-in the good stuff.


In reply to Re: Memory Leak with XS but not pure C by bliako
in thread Memory Leak with XS but not pure C by FrankFooty

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.