From a59fa18fc69fd714097da0fbefe02d42727641f6 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Sun, 5 Jan 2014 16:09:35 -0800 Subject: [PATCH] Make XS::APItest::establish_cleanup protect existing stacks It causes pp_entersub to be called in odd places, which can cause the context stack to be reallocated when an outer function call (like pp_leavesub) has a pointer into the context stack in a C auto. cleanup.t was failing for me under PERL_DEBUG_READONLY_COW + STRESS_REALLOC + threads, because the context stack was reallocated and the old address then freed and reused for something else, being zeroed in the mean time. So pp_leavesub returned NULL (trying to read retop from the context stack), causing the program to exit. During global destruction, subs that had not be exited properly were undefined, leading to: 1..3 Can't undef active subroutine during global destruction. --- ext/XS-APItest/APItest.xs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ext/XS-APItest/APItest.xs b/ext/XS-APItest/APItest.xs index 181b1f6..1b8ec3f 100644 --- a/ext/XS-APItest/APItest.xs +++ b/ext/XS-APItest/APItest.xs @@ -533,12 +533,14 @@ STATIC void THX_run_cleanup(pTHX_ void *cleanup_code_ref) { dSP; + PUSHSTACK; ENTER; SAVETMPS; PUSHMARK(SP); call_sv((SV*)cleanup_code_ref, G_VOID|G_DISCARD); FREETMPS; LEAVE; + POPSTACK; } STATIC OP * -- 2.7.4