[prev in list] [next in list] [prev in thread] [next in thread]
List: perl5-porters
Subject: Re: [perl #124097] Attempt to free unreferenced scalar: SV 0x5eb03f8 (memory corruption)
From: Dave Mitchell <davem () iabyn ! com>
Date: 2015-11-30 11:41:42
Message-ID: 20151130114142.GS2958 () iabyn ! com
[Download RAW message or body]
On Mon, Nov 30, 2015 at 10:14:31AM +1100, Tony Cook wrote:
> On Fri, Nov 27, 2015 at 01:42:30PM +0000, Dave Mitchell wrote:
> > On Wed, Nov 25, 2015 at 08:24:22PM -0800, Tony Cook via RT wrote:
> > > Like the attached?
> >
> > > + /* make sure the GP isn't removed out from under us */
> > > + first_copy = (GV*)newSVsv(MUTABLE_SV(PL_firstgv));
> > > + second_copy = (GV*)newSVsv(MUTABLE_SV(PL_secondgv));
> > > + SAVEFREESV(first_copy);
> > > + SAVEFREESV(second_copy);
> >
> > Wouldn't save_gp(PL_firstgv, 0) be more efficient?
>
> It would, but it also restores the GP to the GV, and the user has
> chosen to replace it - should we be restoring it?
>
> With save_gp:
>
> $ ./perl -e 'sub a { print "hello\n" } a(); @x = sort { *a = sub { print \
> "goodbye\n" }; 1 } 0 .. 1; a();' hello
> hello
>
> With the patch I supplied:
>
> $ ./perl -e 'sub a { print "hello\n" } a(); @x = sort { *a = sub { print \
> "goodbye\n" }; 1 } 0 .. 1; a();' hello
> goodbye
I'd expect sort {block} 1, 2 to have the same semantics as:
{
local *a = \1;
local *b = \2;
{ block }
}
'local *a = ...' does a combination of
save_gp(gv,0) via rv2gv
and
SAVEGENERICSV(SvGV(gv)) via pp_sassign and gv_setref,
so I'd expect some combination of those to Do The Right Thing.
And local does seem to Do The Right Thing:
sub a { print "hello\n" }
a();
{
local *a = \1;
{
*a = sub { print "goodbye\n" };
1;
}
}
a()
prints:
hello
goodbye
So maybe there's a way to achieve this with save_gp?
--
In England there is a special word which means the last sunshine
of the summer. That word is "spring".
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic