From 0f534aaf12174a6c02f455475bef3141f46c221b Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Sun, 25 Nov 2012 13:03:07 -0800 Subject: [PATCH] Stop cv-to-glob assignment redef warnings from leaking We should not increment the reference count of the assignee until we are past the warnings. It should only happen when the reference- counted location is actually made to hold the assignee. At the same time, I changed it to use a more specific variant of SvREFCNT_inc, for speed. --- sv.c | 4 ++-- t/op/svleak.t | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sv.c b/sv.c index a2d29ba..6f75847 100644 --- a/sv.c +++ b/sv.c @@ -3739,7 +3739,7 @@ S_glob_assign_glob(pTHX_ SV *const dstr, SV *const sstr, const int dtype) static void S_glob_assign_ref(pTHX_ SV *const dstr, SV *const sstr) { - SV * const sref = SvREFCNT_inc(SvRV(sstr)); + SV * const sref = SvRV(sstr); SV *dref = NULL; const int intro = GvINTRO(dstr); SV **location; @@ -3825,7 +3825,7 @@ S_glob_assign_ref(pTHX_ SV *const dstr, SV *const sstr) GvASSUMECV_on(dstr); if(GvSTASH(dstr)) mro_method_changed_in(GvSTASH(dstr)); /* sub foo { 1 } sub bar { 2 } *bar = \&foo */ } - *location = sref; + *location = SvREFCNT_inc_simple_NN(sref); if (import_flag && !(GvFLAGS(dstr) & import_flag) && CopSTASH_ne(PL_curcop, GvSTASH(dstr))) { GvFLAGS(dstr) |= import_flag; diff --git a/t/op/svleak.t b/t/op/svleak.t index e3f6be4..a3c14b8 100644 --- a/t/op/svleak.t +++ b/t/op/svleak.t @@ -87,11 +87,11 @@ eleak(2, 0, "no warnings; use feature ':all'; $all my sub foo{} sub foo:lvalue{}", 'fatal mysub redef warning'); eleak(2, 0, "$all sub foo{} sub foo{}", 'fatal sub redef warning'); -$::TODO = 'still leaks'; eleak(2, 0, "$all *x=sub {}", 'fatal sub redef warning with sub-to-glob assignment'); eleak(2, 0, "$all *x=sub() {1}", 'fatal const sub redef warning with sub-to-glob assignment'); +$::TODO = 'still leaks'; eleak(2, 0, "$all XS::APItest::newCONSTSUB(\\%main::=>name=>0=>1)", 'newXS sub redefinition with fatal warnings'); eleak(2, 0, "$f 'misc'; my\$a,my\$a", 'double my with fatal warnings'); -- 2.7.4