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