Blob Blame History Raw
--- ./lib/callable/src/perl/Main.cc.orig	2014-10-13 06:14:22.000000000 -0600
+++ ./lib/callable/src/perl/Main.cc	2015-01-19 12:30:00.000000000 -0700
@@ -37,6 +37,7 @@ namespace {
 
 const char globalScope[]="Polymake::Scope";
 
+static bool need_cleanup;
 GV *globalScope_gv=NULL;
 
 void destroy_perl(pTHXx)
@@ -54,13 +55,14 @@ PerlInterpreter *static_perl = NULL;
 void emergency_cleanup() __attribute__((destructor));
 void emergency_cleanup()
 {
-   if (PL_curinterp) {
+   if (PL_curinterp && need_cleanup) {
 #ifdef PERL_IMPLICIT_CONTEXT
       dTHX;
       destroy_perl(aTHX);
 #else
       destroy_perl(static_perl);
 #endif
+      need_cleanup = false;
    }
 }
 
@@ -158,6 +160,7 @@ Main::Main(const std::string& user_opts,
    pTHXx = perl_alloc();
    PL_perl_destruct_level = 1;
    perl_construct(aTHXx);
+   need_cleanup = true;
    PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
    if (perl_parse(aTHXx, xs_init, argc, (char**)argv, *env)) {
       destroy_perl(aTHXx);