This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
avoid leaked scalar in BEGIN { threads->new(...) }
[perl5.git] / sv.c
diff --git a/sv.c b/sv.c
index 3d4d5b2..06e23ea 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -12425,6 +12425,12 @@ perl_clone_using(PerlInterpreter *proto_perl, UV flags,
 
     SvREFCNT_dec(param->stashes);
 
+    /* orphaned? eg threads->new inside BEGIN or use */
+    if (PL_compcv && ! SvREFCNT(PL_compcv)) {
+       SvREFCNT_inc(PL_compcv);
+       SAVEFREESV(PL_compcv);
+    }
+
     return my_perl;
 }