from perldoc perlguts
in reply to XS malloc and free
You do not free SV, you decrement its usage, and, when refcount goes to zero, it will be destroyed, and may be some destruction-time action will be activated
To free an SV that you've created, call "SvREFCNT_dec(SV*)". Norma
this call is not necessary (see "Reference Counts and Mortality").
addition to free memory out from external library, consult that library's logic. Perl do not uses external char*, it will copy its data into newly created SV
Courage, the Cowardly Dog