From: Dave Mitchell Date: Sat, 30 Oct 2004 23:25:37 +0000 (+0000) Subject: [perl #32033] Using foreach on threads::shared array crashes perl X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=abdac9fa130ffbfb2a187768e4c7ad2ccdd97c0c;p=p5sagit%2Fp5-mst-13.2.git [perl #32033] Using foreach on threads::shared array crashes perl The FETCH code for shared aggregate elements could leak a shared RV address into a private SV. RVs are now handled specially, in the same way that they already were for scalar shared magic. p4raw-id: //depot/perl@23438 --- diff --git a/ext/threads/shared/shared.xs b/ext/threads/shared/shared.xs index 72b7285..2d61d24 100644 --- a/ext/threads/shared/shared.xs +++ b/ext/threads/shared/shared.xs @@ -639,8 +639,18 @@ sharedsv_elem_mg_FETCH(pTHX_ SV *sv, MAGIC *mg) CALLER_CONTEXT; if (svp) { /* Exists in the array */ - target = Perl_sharedsv_associate(aTHX_ &sv, *svp, target); - sv_setsv(sv, *svp); + if (SvROK(*svp)) { + SV *obj = Nullsv; + Perl_sharedsv_associate(aTHX_ &obj, SvRV(*svp), NULL); + sv_setsv_nomg(sv, &PL_sv_undef); + SvRV(sv) = obj; + SvROK_on(sv); + SvSETMAGIC(sv); + } + else { + target = Perl_sharedsv_associate(aTHX_ &sv, *svp, target); + sv_setsv(sv, *svp); + } } else { /* Not in the array */