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:
sthoenna
Date:
February 17, 2003 12:34
Subject:
Re: odd (or not so odd?) segmentation fault in 5.8.0
Message ID:
mXUU+gzkg2kI092yn@efn.org
On Sat, 15 Feb 2003 22:14:22 -0800, sthoenna@efn.org wrote:
>On Thu, 13 Feb 2003 00:38:59 -0500, mark@mark.mielke.cc wrote:
>>I haven't seen this reported yet. I'll try to track it down tomorrow,
>>but in case anybody in the know can point out the problem immediately:
>>
>>$ perl -e 'sub TIESCALAR {bless[]} sub FETCH {*a=\1;1}
>>> tie($a,__PACKAGE__); print $a'
>>zsh: segmentation fault  perl -e
>>
>>Of course, this is an odd thing to do, and therefore, I'm not
>>surprised that there are no regression tests to catch this. My goal
>>was to use a tie() to provide demand loading of an object. The first
>>time through, access is through a tie() that initializes the object,
>>removes the tie, and returns the object. The second time through, and
>>later, the object itself is referenced, and the tie() is gone.
>
>You may be able to get the behaviour you want by returning from FETCH
>an object (with no other references to it) with a DESTROY method that
>unties and sets your tied variable.
>
>The segfault is in mg_get.  Looks to me like after returning from
>FETCH, we have an sv that's already been freed.  The code calls
>SvMAGIC to see if the get func we just called added new magic at the
>head of the list, and that seems to return a garbage pointer (though I
>don't see the segfault until it loops and looks up mg->mg_virtual for
>the "newly added" magic).
>
>You may be able to get things working just by having a $dummy=\$a
>out there so as not to acually free the original sv.

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.

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