in reply to eval_pv leaking

From the perlapi manpage (emphasis mine):

eval_pv Tells Perl to "eval" the given string and return an SV* result.

I tried using
SV* ret = eval_pv("1;", TRUE); SvREFCNT_dec(ret);
but that didn't work (probably because eval_pv works "kindof like a subroutine" in that it returns a mortal SV* - or something; I confess ignorance of the subtleties in perlembedding) - so messed around with the code until I came up with this:
for (;;) { ENTER; SAVETMPS; SV* ret = eval_pv("1;", TRUE); FREETMPS; LEAVE; }

Which doesn't leak for me (perl, v5.8.5 built for i686-linux-thread-multi).

update: this is not really documented AFAIK, probably because you're not likely to be calling eval_* all that much. The perlembed documentation should probably mention something about how to deal with the return value (as it does describe handling the various call_* parameters and return values).

Replies are listed 'Best First'.
Re^2: eval_pv leaking
by PreferredUserName (Pilgrim) on Dec 27, 2004 at 19:40 UTC
    This works for me as well. Thanks!