On Wed, Dec 14, 2011 at 11:30:54PM +0200, Niko Tyni wrote:
> On Sat, Aug 06, 2011 at 08:02:20PM +0200, [email protected] wrote:
>  
> > while trying to get Embperl ready with Perl 5.14.1, I found an the
> > following message in the error log:
> 
> > Attempt to free unreferenced scalar: SV 0x7fc218, Perl interpreter:
> > 0x7cfdb0 during global destruction.
> 
> We're also seeing this in Debian now that we've switched to Perl 5.14,
> (see http://bugs.debian.org/650675 [cc'd.])

> The warnings only seem to happen with -Dusethreads, and I've bisected that
> they started with 5.13.6 - specifically
> 
>  
> http://perl5.git.perl.org/perl.git/commit/ca556bcdca736b2f85c11650c70b2371169c0225

>     [perl #40389] perl_destruct() leaks PL_defstash

> My limited understanding is that the CV pointer needs its refcount
> incremented along with the GvCV_set() call. See the attached proposed
> patch which fixes this for me (but feel free to tell me if I got it all
> wrong :)

Here's another patch in a similar vein. This fixes all the remaining 24
warnings in t/logs/error_log after running the whole test suite.
-- 
Niko Tyni   [email protected]
>From cbf08a2de6f967863d764eb0bc620178c4ed43fe Mon Sep 17 00:00:00 2001
From: Niko Tyni <[email protected]>
Date: Sat, 17 Dec 2011 09:16:22 +0200
Subject: [PATCH 2/2] Fix another reference counting bug uncovered by Perl
 5.13.6

As seen in
 http://bugs.debian.org/650675
 http://article.gmane.org/gmane.comp.apache.mod-perl.devel/9928

perl since 5.13.6 with -Dusethreads makes mod_perl2 issue warnings like

 Attempt to free unreferenced scalar: SV 0x7f9c0c347490, Perl interpreter: 0x7f9c0c1a2dd0 during global de
struction.

An earlier commit fixed some of these in modperl_perl_core_global_init(),
follow the suit with new_constsub().
---
 src/modules/perl/modperl_const.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/src/modules/perl/modperl_const.c b/src/modules/perl/modperl_const.c
index 8732d4f..39a3ec9 100644
--- a/src/modules/perl/modperl_const.c
+++ b/src/modules/perl/modperl_const.c
@@ -51,7 +51,9 @@ static void new_constsub(pTHX_ constants_lookup lookup,
             gv_init(alias, caller_stash, name, name_len, TRUE);
         }
 
-        GvCV_set(alias, GvCV(*gvp));
+        CV *cv = GvCV(*gvp);
+        GvCV_set(alias, cv);
+        SvREFCNT_inc(cv);
     }
 }
 
-- 
1.7.7.3

Reply via email to