This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
locale.c: Free over-allocated space early
authorKarl Williamson <khw@cpan.org>
Sun, 10 Apr 2016 02:40:48 +0000 (20:40 -0600)
committerKarl Williamson <khw@cpan.org>
Tue, 24 May 2016 16:26:29 +0000 (10:26 -0600)
We may over malloc some space in buffers to strxfrm().  This frees it
now instead of waiting for the whole block to be freed sometime later.
This can be a significant amount of memory if the input string to
strxfrm() is long.

locale.c

index 55e43b3..fd46a77 100644 (file)
--- a/locale.c
+++ b/locale.c
@@ -1465,6 +1465,8 @@ Perl_mem_collxfrm(pTHX_ const char *input_string,
 
     *xlen = xout - sizeof(PL_collation_ix);
 
 
     *xlen = xout - sizeof(PL_collation_ix);
 
+    /* Free up unneeded space; retain ehough for trailing NUL */
+    Renew(xbuf, xout + 1, char);
 
     if (s != input_string) {
         Safefree(s);
 
     if (s != input_string) {
         Safefree(s);