in reply to Re^5: perlembed: mortalize an AV or not (misc)
in thread perlembed: mortalize an AV, get "Attempt to free unreferenced scalar" - don't mortalize, leaks memory
dSP; ENTER; SAVETMPS; PUSHMARK(SP); AV *arr = newAV(); av_push( arr, newSVpv("string", 0)); XPUSHs(sv_2mortal(newRV_noinc((SV *)arr))); HV *hash = newHV(); SV *type = newSVpv("string", 0); hv_store( hash, "type", strlen("type"), type, 0); XPUSHs(sv_2mortal(newRV_noinc((SV *)hash))); PUTBACK; call_sv(sv_2mortal(newSVpv("TestPM::test_leak", 0)), G_SCALAR); SPAGAIN; SV *retval = POPs; PUTBACK; FREETMPS; LEAVE;
I'd really appreciate it if you could validate this approach, which is my understanding of what you explained above.
Regarding your other questions:
So wouldn't it be better if I do mortalize everything, and just SvREFCNT_inc whenever I either av_push() or hv_store() the SV, as well as using newRV_inc()? Will that not work and be correct?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^7: perlembed: mortalize an AV or not (misc)
by tye (Sage) on Jul 11, 2006 at 05:52 UTC | |
by tye (Sage) on Jul 11, 2006 at 14:55 UTC | |
by edan (Curate) on Jul 11, 2006 at 06:47 UTC | |
by demerphq (Chancellor) on Jul 11, 2006 at 09:29 UTC | |
by tye (Sage) on Jul 11, 2006 at 15:26 UTC |