Skip to content

Commit

Permalink
Remove non-null checks before op_free()
Browse files Browse the repository at this point in the history
The argument to op_free() is declared NULLOK, and the first thing it
does is return if the op is null or already freed, so there's no point
in callers checking for it.
  • Loading branch information
ilmari committed Sep 19, 2023
1 parent bb3665a commit ee5597d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 26 deletions.
7 changes: 2 additions & 5 deletions class.c
Original file line number Diff line number Diff line change
Expand Up @@ -800,9 +800,7 @@ Perl_class_seal_stash(pTHX_ HV *stash)
if (fieldnames) {
for(SSize_t i = PadnamelistMAX(fieldnames); i >= 0 ; i--) {
PADNAME *pn = PadnamelistARRAY(fieldnames)[i];
OP *valop = PadnameFIELDINFO(pn)->defop;
if (valop)
op_free(valop);
op_free(PadnameFIELDINFO(pn)->defop);
}
}
}
Expand Down Expand Up @@ -1022,8 +1020,7 @@ Perl_class_set_field_defop(pTHX_ PADNAME *pn, OPCODE defmode, OP *defop)

assert(HvSTASH_IS_CLASS(PL_curstash));

if(PadnameFIELDINFO(pn)->defop)
op_free(PadnameFIELDINFO(pn)->defop);
op_free(PadnameFIELDINFO(pn)->defop);

/* set here to ensure clean up if forbid_outofblock_ops() throws */
PadnameFIELDINFO(pn)->defop = defop;
Expand Down
10 changes: 3 additions & 7 deletions op.c
Original file line number Diff line number Diff line change
Expand Up @@ -3998,10 +3998,8 @@ S_move_proto_attr(pTHX_ OP **proto, OP **attrs, const GV * name,
Perl_warner(aTHX_ packWARN(WARN_MISC),
"Attribute prototype(%" UTF8f ") discards earlier prototype attribute in same sub",
UTF8fARG(SvUTF8(cSVOPo_sv), new_len, newp));
op_free(new_proto);
}
else if (new_proto)
op_free(new_proto);
op_free(new_proto);
new_proto = o;
/* excise new_proto from the list */
op_sibling_splice(*attrs, lasto, 1, NULL);
Expand Down Expand Up @@ -4051,8 +4049,7 @@ S_move_proto_attr(pTHX_ OP **proto, OP **attrs, const GV * name,
UTF8fARG(SvUTF8(cSVOPx_sv(new_proto)), new_len, newp),
SVfARG(svname));
}
if (*proto)
op_free(*proto);
op_free(*proto);
*proto = new_proto;
}
}
Expand Down Expand Up @@ -12316,8 +12313,7 @@ Perl_ck_trycatch(pTHX_ OP *o)

/* cut whole sibling chain free from o */
op_sibling_splice(o, NULL, -1, NULL);
if(to_free)
op_free(to_free);
op_free(to_free);
op_free(o);

enter = alloc_LOGOP(OP_ENTERTRYCATCH, NULL, NULL);
Expand Down
7 changes: 3 additions & 4 deletions perl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1903,10 +1903,9 @@ perl_parse(pTHXx_ XSINIT_t xsinit, int argc, char **argv, char **env)
return 0;
}

if (PL_main_root) {
op_free(PL_main_root);
PL_main_root = NULL;
}
op_free(PL_main_root);
PL_main_root = NULL;

PL_main_start = NULL;
SvREFCNT_dec(PL_main_cv);
PL_main_cv = NULL;
Expand Down
8 changes: 4 additions & 4 deletions pp_ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -4112,10 +4112,10 @@ S_doeval_compile(pTHX_ U8 gimme, CV* outside, U32 seq, HV *hh)

if (!in_require)
invoke_exception_hook(ERRSV,FALSE);
if (PL_eval_root) {
op_free(PL_eval_root);
PL_eval_root = NULL;
}

op_free(PL_eval_root);
PL_eval_root = NULL;

rpp_popfree_to(PL_stack_base + POPMARK); /* pop original mark */
cx = CX_CUR();
assert(CxTYPE(cx) == CXt_EVAL);
Expand Down
9 changes: 3 additions & 6 deletions toke.c
Original file line number Diff line number Diff line change
Expand Up @@ -6162,8 +6162,7 @@ yyl_colon(pTHX_ char *s)
if (*d == '(') {
d = scan_str(d,TRUE,TRUE,FALSE,NULL);
if (!d) {
if (attrs)
op_free(attrs);
op_free(attrs);
ASSUME(sv && SvREFCNT(sv) == 1);
SvREFCNT_dec(sv);
Perl_croak(aTHX_ "Unterminated attribute parameter in attribute list");
Expand Down Expand Up @@ -6211,17 +6210,15 @@ yyl_colon(pTHX_ char *s)
? Perl_form(aTHX_ "Invalid separator character "
"%c%c%c in attribute list", q, *s, q)
: "Unterminated attribute list" ) );
if (attrs)
op_free(attrs);
op_free(attrs);
OPERATOR(PERLY_COLON);
}

got_attrs:
if (PL_parser->sig_seen) {
/* see comment about about sig_seen and parser error
* handling */
if (attrs)
op_free(attrs);
op_free(attrs);
Perl_croak(aTHX_ "Subroutine attributes must come "
"before the signature");
}
Expand Down

0 comments on commit ee5597d

Please sign in to comment.