diff options
author | Father Chrysostomos <sprout@cpan.org> | 2012-01-09 19:54:26 -0800 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2012-01-09 19:54:26 -0800 |
commit | 60edcf09a5cb026822f99270a4bfbe3149cfbb52 (patch) | |
tree | 9651ece6289498ae99ca78bc4da131b5c22be3b6 /hv.c | |
parent | f09f972badf5b299d86c10b00897652752e314ed (diff) | |
download | perl-60edcf09a5cb026822f99270a4bfbe3149cfbb52.tar.gz |
Better fix for perl #107440
> > Actually, the simplest solution seem to be to put the av or hv on
> > the mortals stack in pp_aassign and pp_undef, rather than in
> > [ah]v_undef/clear.
>
> This makes me nervous. The tmps stack is typically cleared only on
> statement boundaries, so we run the risks of
>
> * user-visible delaying of freeing elements;
> * large tmps stack growth might be possible with
> certain types of loop that repeatedly assign to an array without
> freeing tmps (eg map? I think I fixed most map/grep tmps leakage
> a
> while back, but there may still be some edge cases).
>
> Surely an ENTER/SAVEFREESV/LEAVE inside pp_aassign is just as
> efficient,
> without any attendant risks?
>
> Also, although pp_aassign and pp_undef are now fixed, the
> [ah]v_undef/clear functions aren't, and they're part of the public API
> that can be called independently of pp_aassign etc. Ideally they
> should
> be fixed (so they don't crash in mid-loop), and their documentation
> updated to point out that on return, their AV/HV arg may have been
> freed.
This commit takes care of the first part; it changes pp_aassign to use
ENTER/SAVEFREESV/LEAVE and adds the same to h_freeentries (called both
by hv_undef and hv_clear), av_undef and av_clear.
It effectively reverts the C code part of 9f71cfe6ef2.
Diffstat (limited to 'hv.c')
-rw-r--r-- | hv.c | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -1681,12 +1681,20 @@ S_hfreeentries(pTHX_ HV *hv) STRLEN index = 0; XPVHV * const xhv = (XPVHV*)SvANY(hv); SV *sv; + const bool save = !!SvREFCNT(hv); PERL_ARGS_ASSERT_HFREEENTRIES; + if (save) { + ENTER; + SAVEFREESV(SvREFCNT_inc_simple_NN(hv)); + } + while ((sv = Perl_hfree_next_entry(aTHX_ hv, &index))||xhv->xhv_keys) { SvREFCNT_dec(sv); } + + if (save) LEAVE; } |