This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add assertions to S_curse in sv.c
authorFather Chrysostomos <sprout@cpan.org>
Tue, 20 Nov 2012 22:43:43 +0000 (14:43 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Wed, 21 Nov 2012 01:58:58 +0000 (17:58 -0800)
If anything should go wrong with the order things are freed, we
could get crashes from this code.  The assertions seem like a
good idea.

sv.c

diff --git a/sv.c b/sv.c
index a791498..e87d80a 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -6334,6 +6334,7 @@ S_curse(pTHX_ SV * const sv, const bool check_refcnt) {
        do {
          if ((stash = SvSTASH(sv)) && HvNAME(stash)) {
            CV* destructor = NULL;
+           assert(SvTYPE(stash) == SVt_PVHV);
            if (!SvOBJECT(stash)) destructor = (CV *)SvSTASH(stash);
            if (!destructor) {
                GV * const gv =
@@ -6362,6 +6363,7 @@ S_curse(pTHX_ SV * const sv, const bool check_refcnt) {
               )
            {
                SV* const tmpref = newRV(sv);
+               assert(SvTYPE(destructor) == SVt_PVCV);
                SvREADONLY_on(tmpref); /* DESTROY() could be naughty */
                ENTER;
                PUSHSTACKi(PERLSI_DESTROY);