This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #114368] perl -DA -e '' segfaults
authorFather Chrysostomos <sprout@cpan.org>
Wed, 1 Aug 2012 20:04:14 +0000 (13:04 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 2 Aug 2012 03:38:17 +0000 (20:38 -0700)
Iterative freeing of hashes uses the SvMAGIC field for a different
purpose.  So clear it before calling hv_undef_flags, which calls
hv_assert, which expects any non-null value fo SvMAGIC to me magic.

sv.c

diff --git a/sv.c b/sv.c
index 0d99ec6..4ab14e3 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -6240,6 +6240,10 @@ Perl_sv_clear(pTHX_ SV *const orig_sv)
                    iter_sv = (SV*)SvSTASH(sv);
                    assert(!SvMAGICAL(sv));
                    hash_index = ((XPVMG*) SvANY(sv))->xmg_u.xmg_hash_index;
+#ifdef DEBUGGING
+                   /* perl -DA does not like rubbish in SvMAGIC. */
+                   SvMAGIC_set(sv, 0);
+#endif
 
                    /* free any remaining detritus from the hash struct */
                    Perl_hv_undef_flags(aTHX_ MUTABLE_HV(sv), HV_NAME_SETALL);