Hi Monks,

Debugging some memory leaks in a code with XS I have been reading perldoc perlxs guide to use DESTROY for freeing objects that get out of scope in perl. However my DESTROY function is never invoked and I can not understand why.

In the XS code there is a function "_new_from_der" that allocates memory and return it as a object "OpenCA_OpenSSL_CRL":

###################################################################### +### MODULE = OpenCA::OpenSSL PACKAGE = OpenCA::OpenSSL::CRL OpenCA_OpenSSL_CRL _new_from_der(SV * sv)

This object is typemapped in what I understand is substitution of "_" for "::"

Typemap is:

OpenCA_OpenSSL_CRL T_PTROBJ_SPECIAL INPUT T_PTROBJ_SPECIAL if (sv_derived_from($arg, \"${(my $ntt=$ntype)=~s/_/::/g;\$ntt +}\")) { IV tmp = SvIV((SV*)SvRV($arg)); $var = INT2PTR($type,tmp); } else croak(\"$var is not of type ${(my $ntt=$ntype)=~s/_/:: +/g;\$ntt}\") OUTPUT T_PTROBJ_SPECIAL sv_setref_pv($arg, \"${(my $ntt=$ntype)=~s/_/::/g;\$ntt}\", (void*)$var);

And typedef:

typedef X509_CRL * OpenCA_OpenSSL_CRL;

So, following the perlxs doc I inserted this DESTROY:

###################################################################### +### MODULE = OpenCA::OpenSSL PACKAGE = OpenCA::OpenSSL::CRL +Ptr PREFIX = some_ void some_DESTROY(crl) OpenCA_OpenSSL_CRL crl CODE: fprintf(stderr, "DESTROY\n"); X509_CRL_free(crl);

But the DESTROY function is never invoked.

The main perl invocation is like this:

sub test { my $crl; $crl = OpenCA::OpenSSL::CRL::_new_from_der ($keys->{DATA}); }

I also tried using PACKAGE = OpenCA_OpenSSL_CRLPtr with no luck.

What I am doing wrong?

Regards,
Carlos Velasco

In reply to XS DESTROY not invoked by CarlosV

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.