This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #40389] perl_destruct() leaks PL_defstash
[perl5.git] / perl.c
diff --git a/perl.c b/perl.c
index 985ddf3..860cdfc 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -574,7 +574,7 @@ perl_destruct(pTHXx)
     /* Need to flush since END blocks can produce output */
     my_fflush_all();
 
-    if (CALL_FPTR(PL_threadhook)(aTHX)) {
+    if (PL_threadhook(aTHX)) {
         /* Threads hook has vetoed further cleanup */
        PL_veto_cleanup = TRUE;
         return STATUS_EXIT;
@@ -1042,6 +1042,8 @@ perl_destruct(pTHXx)
     /* Prepare to destruct main symbol table.  */
 
     hv = PL_defstash;
+    /* break ref loop  *:: <=> %:: */
+    (void)hv_delete(hv, "main::", 6, G_DISCARD);
     PL_defstash = 0;
     SvREFCNT_dec(hv);
     SvREFCNT_dec(PL_curstname);
@@ -1071,6 +1073,12 @@ perl_destruct(pTHXx)
                             (long)cxstack_ix + 1);
     }
 
+#ifdef PERL_IMPLICIT_CONTEXT
+    /* the entries in this list are allocated via SV PVX's, so get freed
+     * in sv_clean_all */
+    Safefree(PL_my_cxt_list);
+#endif
+
     /* Now absolutely destruct everything, somehow or other, loops or no. */
 
     /* the 2 is for PL_fdpid and PL_strtab */
@@ -1664,6 +1672,9 @@ S_Internals_V(pTHX_ CV *cv)
 #  ifdef PERL_DONT_CREATE_GVSV
                             " PERL_DONT_CREATE_GVSV"
 #  endif
+#  ifdef PERL_EXTERNAL_GLOB
+                            " PERL_EXTERNAL_GLOB"
+#  endif
 #  ifdef PERL_IS_MINIPERL
                             " PERL_IS_MINIPERL"
 #  endif
@@ -2159,7 +2170,7 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit)
     /* now parse the script */
 
     SETERRNO(0,SS_NORMAL);
-    if (yyparse() || PL_parser->error_count) {
+    if (yyparse(GRAMPROG) || PL_parser->error_count) {
        if (PL_minus_c)
            Perl_croak(aTHX_ "%s had compilation errors.\n", PL_origfilename);
        else {