diff options
author | Father Chrysostomos <sprout@cpan.org> | 2012-10-25 13:00:55 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2012-10-25 20:02:55 -0700 |
commit | 3ed356df9354193bbcc5202f066f3c07ae84b443 (patch) | |
tree | 6a9fd54462d581f52672a517b461498fb798166e /av.c | |
parent | 33b889b0162a4f12e7c2a8d184afb63213130f07 (diff) | |
download | perl-3ed356df9354193bbcc5202f066f3c07ae84b443.tar.gz |
[perl #115440] Fix various leaks with fatal FETCH
Various pieces of code were creating an SV and then assigning to it
from a value that might be magical. If the source scalar is magical,
it could die when magic is called, leaking the scalar that would have
been assigned to.
So we call get-magic before creating the new scalar, and then use a
non-magical assignment.
Also, anonhash and anonlist were doing nothing to protect the aggre-
gate if an argument should die on FETCH, resulting in a leak.
Diffstat (limited to 'av.c')
-rw-r--r-- | av.c | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -412,7 +412,10 @@ Perl_av_make(pTHX_ register I32 size, register SV **strp) Newx(ary,size,SV*); AvALLOC(av) = ary; AvARRAY(av) = ary; - AvFILLp(av) = AvMAX(av) = size - 1; + AvMAX(av) = size - 1; + AvFILLp(av) = -1; + ENTER; + SAVEFREESV(av); for (i = 0; i < size; i++) { assert (*strp); @@ -420,11 +423,15 @@ Perl_av_make(pTHX_ register I32 size, register SV **strp) have multiple references to the same temp scalar (e.g. from a list slice) */ + SvGETMAGIC(*strp); /* before newSV, in case it dies */ + AvFILLp(av)++; ary[i] = newSV(0); sv_setsv_flags(ary[i], *strp, - SV_GMAGIC|SV_DO_COW_SVSETSV|SV_NOSTEAL); + SV_DO_COW_SVSETSV|SV_NOSTEAL); strp++; } + SvREFCNT_inc_simple_void_NN(av); + LEAVE; } return av; } |