develooper Front page | perl.perl5.porters | Postings from May 2008

Re: [perl #54934] Attempt to free unreferenced scalar fiddling with the symbol table

Thread Previous | Thread Next
From:
Rafael Garcia-Suarez
Date:
May 30, 2008 05:55
Subject:
Re: [perl #54934] Attempt to free unreferenced scalar fiddling with the symbol table
Message ID:
b77c1dce0805300555l3997e620saaba26bdee2543dc@mail.gmail.com
2008/5/27 via RT Niko Tyni <perlbug-followup@perl.org>:
> As seen in <http://cpantesters.perl.org/show/PerlIO-via-dynamic.html>,
> the test suite of the PerlIO::via::dynamic CPAN module generates
> 'Attempt to free unreferenced scalar' warnings with recent perl versions,
> including 5.10.0 but not 5.8.8.
>
> The warnings are still there on blead @33937; bisecting shows the warnings
> started with
>
>  Change 24966 by nicholas@ship-in-a-bottle on 2005/06/23 21:30:33
>
>  Remove the reference loop between symbol tables and typeglobs. Typeglobs
>  now have a weak reference onto their symbol table.
>
> This snippet is the smallest I can make it. The original code deletes
> a dynamically created package instead which makes more sense than this.
>
> #!/usr/bin/perl
> package test;
> sub PUSHED {
>    return \*FOO;
> }
> 1;
> package main;
> {
>    open my $fh, '</';
>    binmode($fh, ':via(test)');
> }
> delete $::{'test::'};

Good catch. I've traced the double-freed scalar; the patch below fixes
the error. However I'm not sure at all it creates no leak.

--- ext/PerlIO/via/via.xs.orig	2008-01-25 10:00:53.000000000 +0100
+++ ext/PerlIO/via/via.xs	2008-05-30 14:43:11.000000000 +0200
@@ -89,7 +89,7 @@ PerlIOVia_method(pTHX_ PerlIO * f, const
 	    if (!s->fh) {
 		GV *gv = newGVgen(HvNAME_get(s->stash));
 		GvIOp(gv) = newIO();
-		s->fh = newRV_noinc((SV *) gv);
+		s->fh = newRV((SV *) gv);
 		s->io = GvIOp(gv);
 	    }
 	    IoIFP(s->io) = PerlIONext(f);
End of Patch.

So what leaks is a gv generated to hold the "FOO" reference. (Its name
is "_GEN_0".)

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About