G
gmlvsk2
Simple code that creates new hash and put {'foo'=>5} to it
This works and prints 5, but does not release variable sv, so there is
memory leak
some function
HV *hv;
SV *sv = newSViv(5);
hv = newHV();
hv_store( hv, "foo", 3, sv, 0 );
return sv_2mortal( newRV((SV*)hv) );
If I change line 2 to
SV *sv = sv_2mortal( newSViv(5) );
I get undef instead of 5 during print, but the variable is released.
What do I do wrong here, how can mark variable for relese but still be
able to use it from hash
__________________________________________________
Perl to test
use Try;
use Data:umper;
$a = Try::foo();
#print $a->{'foo'}, "\n";
print Dumper( $a );
This works and prints 5, but does not release variable sv, so there is
memory leak
some function
HV *hv;
SV *sv = newSViv(5);
hv = newHV();
hv_store( hv, "foo", 3, sv, 0 );
return sv_2mortal( newRV((SV*)hv) );
If I change line 2 to
SV *sv = sv_2mortal( newSViv(5) );
I get undef instead of 5 during print, but the variable is released.
What do I do wrong here, how can mark variable for relese but still be
able to use it from hash
__________________________________________________
Perl to test
use Try;
use Data:umper;
$a = Try::foo();
#print $a->{'foo'}, "\n";
print Dumper( $a );