In perl.git, the branch blead has been updated <https://perl5.git.perl.org/perl.git/commitdiff/59c73bd3d62c5096a6f9b2e3cbe05e1ab4c158cf?hp=387e2cd4d0d0ac027048044a6c2f046eb1be946f>
- Log ----------------------------------------------------------------- commit 59c73bd3d62c5096a6f9b2e3cbe05e1ab4c158cf Author: David Mitchell <[email protected]> Date: Thu Jul 11 15:17:48 2019 +0100 threads::shared: fix leak When assigning a shared reference value to a variable containing a shared string, the PV buffer in the shared space was leaked. For example: my $s :shared = "foo"; my $t :shared = shared_clone(\"bar"); $s = $t; # "foo" in shared space leaked This was showing up as failed smokes under ASan. ----------------------------------------------------------------------- Summary of changes: dist/threads-shared/lib/threads/shared.pm | 4 ++-- dist/threads-shared/shared.xs | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/dist/threads-shared/lib/threads/shared.pm b/dist/threads-shared/lib/threads/shared.pm index 45ad154979..bd0e4372cf 100644 --- a/dist/threads-shared/lib/threads/shared.pm +++ b/dist/threads-shared/lib/threads/shared.pm @@ -8,7 +8,7 @@ use Config; use Scalar::Util qw(reftype refaddr blessed); -our $VERSION = '1.60'; # Please update the pod, too. +our $VERSION = '1.61'; # Please update the pod, too. my $XS_VERSION = $VERSION; $VERSION = eval $VERSION; @@ -196,7 +196,7 @@ threads::shared - Perl extension for sharing data structures between threads =head1 VERSION -This document describes threads::shared version 1.60 +This document describes threads::shared version 1.61 =head1 SYNOPSIS diff --git a/dist/threads-shared/shared.xs b/dist/threads-shared/shared.xs index 6cdf094d27..858c6d62fd 100644 --- a/dist/threads-shared/shared.xs +++ b/dist/threads-shared/shared.xs @@ -818,12 +818,19 @@ sharedsv_scalar_store(pTHX_ SV *sv, SV *ssv) SV *obj = SvRV(sv); SV *sobj = Perl_sharedsv_find(aTHX_ obj); if (sobj) { + SV* tmpref; SHARED_CONTEXT; - (void)SvUPGRADE(ssv, SVt_RV); - sv_setsv_nomg(ssv, &PL_sv_undef); + /* Creating a tmp ref to sobj then assigning it to ssv ensures + * that any previous contents of ssv are correctly freed + * by sv_setsv(). Not sure if there is a better, API-legal way + * to achieve this */ + tmpref = newSV_type(SVt_RV); + SvRV_set(tmpref, sobj); + SvROK_on(tmpref); + SvREFCNT_inc_simple_NN(sobj); + sv_setsv_nomg(ssv, tmpref); + SvREFCNT_dec_NN(tmpref); - SvRV_set(ssv, SvREFCNT_inc(sobj)); - SvROK_on(ssv); if (SvOBJECT(sobj)) { /* Remove any old blessing */ SvREFCNT_dec(SvSTASH(sobj)); -- Perl5 Master Repository
