diff options
author | Daniel Dragan <bulk88@hotmail.com> | 2015-07-29 03:31:23 -0400 |
---|---|---|
committer | Tony Cook <tony@develop-help.com> | 2015-08-03 11:50:54 +1000 |
commit | 997c424a5725c6a1ddfcced6f5d13535e970f842 (patch) | |
tree | 968e36f2ccaacdb6ee4ddf8d90b4ca67e2a8756e /pp.c | |
parent | c0b7e5912401cf8f1eedc72206b90e6f1623729a (diff) | |
download | perl-997c424a5725c6a1ddfcced6f5d13535e970f842.tar.gz |
Safefree(NULL) reduction
locale.c:
- the pointers are always null at this point, see
http://www.nntp.perl.org/group/perl.perl5.porters/2015/07/msg229533.html
pp.c:
- reduce scope of temp_buffer and svrecode, into an inner branch
- in some permutations, either temp_buffer is never set to non-null, or
svrecode, in permutations where it is known that the var hasn't been set
yet, skip the freeing calls at the end, this doesn't eliminate all
permutations with NULL being passed to Safefree and SvREFCNT_dec, but
only some of them
regcomp.c
- dont create a save stack entry to call Safefree(NULL), see ticket for
this patch for some profiling stats
Diffstat (limited to 'pp.c')
-rw-r--r-- | pp.c | 31 |
1 files changed, 16 insertions, 15 deletions
@@ -817,14 +817,13 @@ S_do_chomp(pTHX_ SV *retval, SV *sv, bool chomping) s = SvPV(sv, len); if (chomping) { - char *temp_buffer = NULL; - SV *svrecode = NULL; - if (s && len) { + char *temp_buffer = NULL; + SV *svrecode = NULL; s += --len; if (RsPARA(PL_rs)) { if (*s != '\n') - goto nope; + goto nope_free_nothing; ++count; while (len && s[-1] == '\n') { --len; @@ -848,11 +847,12 @@ S_do_chomp(pTHX_ SV *retval, SV *sv, bool chomping) temp_buffer = (char*)bytes_from_utf8((U8*)rsptr, &rslen, &is_utf8); if (is_utf8) { - /* Cannot downgrade, therefore cannot possibly match + /* Cannot downgrade, therefore cannot possibly match. + At this point, temp_buffer is not alloced, and + is the buffer inside PL_rs, so dont free it. */ assert (temp_buffer == rsptr); - temp_buffer = NULL; - goto nope; + goto nope_free_sv; } rsptr = temp_buffer; } @@ -872,16 +872,16 @@ S_do_chomp(pTHX_ SV *retval, SV *sv, bool chomping) } if (rslen == 1) { if (*s != *rsptr) - goto nope; + goto nope_free_all; ++count; } else { if (len < rslen - 1) - goto nope; + goto nope_free_all; len -= rslen - 1; s -= rslen - 1; if (memNE(s, rsptr, rslen)) - goto nope; + goto nope_free_all; count += rs_charlen; } } @@ -890,12 +890,13 @@ S_do_chomp(pTHX_ SV *retval, SV *sv, bool chomping) *SvEND(sv) = '\0'; SvNIOK_off(sv); SvSETMAGIC(sv); - } - nope: - SvREFCNT_dec(svrecode); - - Safefree(temp_buffer); + nope_free_all: + Safefree(temp_buffer); + nope_free_sv: + SvREFCNT_dec(svrecode); + nope_free_nothing: ; + } } else { if (len && (!SvPOK(sv) || SvIsCOW(sv))) s = SvPV_force_nomg(sv, len); |