Yeah, XS is extremely difficult to do correctly. I don't see where your code causes a leak (not surprising, since this is usually quite complicated to figure out). So you would be wise to minimize the amount of XS code you write. For example, have a Perl wrapper that uses a simple pack and unpack and eliminate almost all of the "manipulate Perl internal data structure" stuff from your XS:

char * top_insert( up, down, init_step_ratio, ratio ) char * up char * down double init_step_ratio double ratio INIT: int up_num, down_num, sample_num; double *return_val = NULL; PPCODE: up_num = {length of arg 0}/sizeof(double)/3; down_num = {length of arg 1}/sizeof(double)/3; return_val = get_inter_line( up_num, (double*)up, down_num, (double*)down, init_step_ratio, ratio, &sample_num ); sample_num *= 3; {set return value SV to: copy of return_val w/ length sample_num*sizeof(double)} del_inter_line(return_val);

(The few bits of dealing with Perl internal data structures left as an exercise above as I don't have those memorized.)

- tye        


In reply to Re: xs memoryleak (xs--) by tye
in thread xs memoryleak by yarp

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.