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,In reply to XS DESTROY not invoked by CarlosV
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |