From bc62bf8519f9005df2fb29dbd3d330202b258b6b Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Sat, 1 Jun 2019 14:39:55 -0600 Subject: Add some defensive coding to av_store() Don't decrement the reference count of the element about to be stored into. Likely, this is an error in the caller, but doing this action blindly is like shooting yourself in the foot. The branch prediction also added ensures this shouldn't slow things down. See http://nntp.perl.org/group/perl.perl5.porters/254974 --- av.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'av.c') diff --git a/av.c b/av.c index 918844c376..f10f1247f4 100644 --- a/av.c +++ b/av.c @@ -356,8 +356,8 @@ Perl_av_store(pTHX_ AV *av, SSize_t key, SV *val) } AvFILLp(av) = key; } - else if (AvREAL(av)) - SvREFCNT_dec(ary[key]); + else if (AvREAL(av) && LIKELY(ary[key] != val)) + SvREFCNT_dec(ary[key]); ary[key] = val; if (SvSMAGICAL(av)) { const MAGIC *mg = SvMAGIC(av); -- cgit v1.2.1