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

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

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
February 17, 2003 12:56
Subject:
Re: odd (or not so odd?) segmentation fault in 5.8.0
Message ID:
20030217205250.D14740@fdgroup.com
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 :-(

-- 
"Do not dabble in paradox, Edward, it puts you in danger of fortuitous
wit." Lady Croom - Arcadia



--- 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