This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Allocate MADPROPs using PerlMemShared_malloc()
authorNicholas Clark <nick@ccl4.org>
Mon, 11 Apr 2011 19:14:34 +0000 (20:14 +0100)
committerNicholas Clark <nick@ccl4.org>
Thu, 19 May 2011 07:55:56 +0000 (08:55 +0100)
As the MADPROPs are referenced from the optree, which is itself shared,
MADPROPs can't use the default malloc(), which is per i-thread, lest a
child thread frees the optree, and bad things(tm) happen. (a "free to wrong
pool" panic if you're on Win32, or elsewhere if you've got DEBUGGING)

op.c

diff --git a/op.c b/op.c
index e21b9a4..5740aa6 100644 (file)
--- a/op.c
+++ b/op.c
@@ -3139,8 +3139,7 @@ Perl_newMADsv(pTHX_ char key, SV* sv)
 MADPROP *
 Perl_newMADPROP(pTHX_ char key, char type, void* val, I32 vlen)
 {
-    MADPROP *mp;
-    Newxz(mp, 1, MADPROP);
+    MADPROP *const mp = (MADPROP *) PerlMemShared_malloc(sizeof(MADPROP));
     mp->mad_next = 0;
     mp->mad_key = key;
     mp->mad_vlen = vlen;
@@ -3177,7 +3176,7 @@ Perl_mad_free(pTHX_ MADPROP* mp)
        PerlIO_printf(PerlIO_stderr(), "Unrecognized mad\n");
        break;
     }
-    Safefree(mp);
+    PerlMemShared_free(mp);
 }
 
 #endif