@@ -3888,7 +3888,7 @@ S_apply_attrs(pTHX_ HV *stash, SV *target, OP *attrs)
38883888
38893889 Perl_load_module(
38903890 aTHX_ PERL_LOADMOD_IMPORT_OPS,
3891- newSVpvs (ATTRSMODULE),
3891+ newSVpvs_share (ATTRSMODULE),
38923892 NULL,
38933893 op_prepend_elem(OP_LIST,
38943894 newSVOP(OP_CONST, 0, stashsv),
@@ -3903,7 +3903,7 @@ STATIC void
39033903S_apply_attrs_my(pTHX_ HV *stash, OP *target, OP *attrs, OP **imopsp)
39043904{
39053905 OP *pack, *imop, *arg;
3906- SV *meth, *stashsv, **svp;
3906+ SV *meth, *stashsv, *attrpkg, * *svp;
39073907
39083908 PERL_ARGS_ASSERT_APPLY_ATTRS_MY;
39093909
@@ -3914,17 +3914,23 @@ S_apply_attrs_my(pTHX_ HV *stash, OP *target, OP *attrs, OP **imopsp)
39143914 target->op_type == OP_PADHV ||
39153915 target->op_type == OP_PADAV);
39163916
3917+ attrpkg = newSVpvs_share(ATTRSMODULE);
3918+ /* no sv_2mortal() or its freed by time of leave_scope() -> replace_sv() */
3919+ SAVEFREESV(attrpkg);
3920+
39173921 /* Ensure that attributes.pm is loaded. */
39183922 /* Don't force the C<use> if we don't need it. */
39193923 svp = hv_fetchs(GvHVn(PL_incgv), ATTRSMODULE_PM, FALSE);
39203924 if (svp && *svp != &PL_sv_undef)
39213925 NOOP; /* already in %INC */
3922- else
3923- Perl_load_module(aTHX_ PERL_LOADMOD_NOIMPORT,
3924- newSVpvs(ATTRSMODULE), NULL);
3926+ else {
3927+ SvREFCNT_inc_simple_void_NN(attrpkg);
3928+ Perl_load_module(aTHX_ PERL_LOADMOD_NOIMPORT, attrpkg, NULL);
3929+ }
39253930
39263931 /* Need package name for method call. */
3927- pack = newSVOP(OP_CONST, 0, newSVpvs(ATTRSMODULE));
3932+ SvREFCNT_inc_simple_void_NN(attrpkg);
3933+ pack = newSVOP(OP_CONST, 0, attrpkg);
39283934
39293935 /* Build up the real arg-list. */
39303936 stashsv = newSVhek(HvNAME_HEK(stash));
@@ -3989,7 +3995,7 @@ Perl_apply_attrs_string(pTHX_ const char *stashpv, CV *cv,
39893995 }
39903996
39913997 Perl_load_module(aTHX_ PERL_LOADMOD_IMPORT_OPS,
3992- newSVpvs (ATTRSMODULE),
3998+ newSVpvs_share (ATTRSMODULE),
39933999 NULL, op_prepend_elem(OP_LIST,
39944000 newSVOP(OP_CONST, 0, newSVpv(stashpv,0)),
39954001 op_prepend_elem(OP_LIST,
0 commit comments