Skip to content

Commit

Permalink
magic_setsubstr: Use bytes_to_utf8_free_me
Browse files Browse the repository at this point in the history
This can avoid a malloc
  • Loading branch information
khwilliamson committed Jan 29, 2025
1 parent c7c038a commit e7a6a02
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions mg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2572,9 +2572,10 @@ Perl_magic_setsubstr(pTHX_ SV *sv, MAGIC *mg)
const char *utf8;
lvoff = sv_pos_u2b_flags(lsv, lvoff, &lvlen, SV_CONST_RETURN);
newtarglen = len;
utf8 = (char*)bytes_to_utf8((U8*)tmps, &len);
void * free_me = NULL;
utf8 = (char*)bytes_to_utf8_free_me((U8*)tmps, &len, &free_me);
sv_insert_flags(lsv, lvoff, lvlen, utf8, len, 0);
Safefree(utf8);
Safefree(free_me);
}
else {
sv_insert_flags(lsv, lvoff, lvlen, tmps, len, 0);
Expand Down

0 comments on commit e7a6a02

Please sign in to comment.