develooper Front page | perl.perl5.porters | Postings from March 2003

Re: odd (or not so odd?) segmentation fault in 5.8.0

Thread Previous | Thread Next
From:
sthoenna
Date:
March 7, 2003 00:42
Subject:
Re: odd (or not so odd?) segmentation fault in 5.8.0
Message ID:
8HFa+gzkg+iP092yn@efn.org
On Mon, 17 Feb 2003 20:52:50 +0000, davem@fdgroup.com wrote:
>On Mon, Feb 17, 2003 at 12:28:22PM -0800, Yitzchak Scott-Thoennes wrote:
>> The original bug above (the sv being freed in the middle of a FETCH
>> call, resulting in a coredump) may be fixed by a refcnt inc in
>> save_magic and a corresponding dec as the last thing in restore_magic.
>> My bleadperl isn't up to date...perhaps someone else could give it a
>> shot.
>
>I had a quick try, and make test gave lots of 'scalars leaked', and I
>haven't the enthusiam to look into further at the moment :-(

:( Lots indeed.  Thanks for giving it a try.

Somehow, we are getting lots of calls to save_magic for sv's with a 0
refcnt (!).  Adding a "if (!PL_dirty) " before the _inc and _dec calls
makes most (but not all) of the errors go away.

But this may be the wrong approach anyway.  It keeps the sv around
until the end of the magic stuff, which solves the coredump for
something like "print $a", but "$a .= 'foo'" is going to end up
segfaulting later anyway.  A different patch forthcoming.

>--- mg.c-	Mon Feb 17 20:51:09 2003
>+++ mg.c	Mon Feb 17 20:54:49 2003
>@@ -66,6 +66,10 @@ S_save_magic(pTHX_ I32 mgs_ix, SV *sv)
>     if (SvIsCOW(sv))
>       sv_force_normal(sv);
> #endif
>+    /* add an extra ref, to stop for example, FETCH() freeing the thing
>+     * being referenced. This ref is removed by restore_magic() */
>+
>+    SvREFCNT_inc(sv);
> 
>     SAVEDESTRUCTOR_X(restore_magic, INT2PTR(void*, (IV)mgs_ix));
> 
>@@ -2502,6 +2506,8 @@ restore_magic(pTHX_ void *p)
> 	popval = SSPOPINT;
>         PL_savestack_ix -= popval;
>     }
>+    /* remove the extra ref added by save_magic() */
>+    SvREFCNT_dec(sv);
> 
> }
> 

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