/* attach the anon CV to the pad so that
* pad_fixup_inner_anons() can find it */
- (void)pad_add_anon(cv, o->op_type);
+ if (cv) (void)pad_add_anon(cv, o->op_type);
SvREFCNT_inc_simple_void(cv);
}
else {
if (ec) {
op_free(block);
- cv = PL_compcv;
+ SvREFCNT_dec(PL_compcv);
+ PL_compcv = 0;
if (name && block) {
const char *s = strrchr(name, ':');
s = s ? s+1 : name;
if (strEQ(s, "BEGIN")) {
const char not_safe[] =
"BEGIN not safe after errors--compilation aborted";
- PL_compcv = 0;
- SvREFCNT_dec(cv);
if (PL_in_eval & EVAL_KEEPERR)
Perl_croak(aTHX_ not_safe);
else {
{
PERL_ARGS_ASSERT_CK_ANONCODE;
+ /* After errors, we won’t have any sub. */
+ if (!cSVOPo->op_sv) return o;
+
cSVOPo->op_targ = pad_add_anon((CV*)cSVOPo->op_sv, o->op_type);
if (!PL_madskills)
cSVOPo->op_sv = NULL;
use Config;
-plan tests => 64;
+plan tests => 65;
# run some code N times. If the number of SVs at the end of loop N is
# greater than (N-1)*delta at the end of loop 1, we've got a leak
}
eleak(2, 0, '+sub:a{}', 'anon subs with invalid attributes');
+eleak(2, 0, 'no warnings; sub a{1 1}', 'sub with syntax error');
# Syntax errors
eleak(2, 0, '"${<<END}"