From: Karl Williamson Date: Fri, 16 Apr 2010 03:32:27 +0000 (-0600) Subject: PATCH: memory leak introduced in 5.12.0 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6e1bad6cc227c8e8;p=p5sagit%2Fp5-mst-13.2.git PATCH: memory leak introduced in 5.12.0 There is a small possibility of a memory leak in toke.c when there is a deprecated character in the name in a \N{...} construct, and the Perl is embedded or something like that so that memory isn't freed up when it exits. This patch avoids the creation of a new scalar, and gives a better error message besides. --- diff --git a/pod/perldiag.pod b/pod/perldiag.pod index fe9be76..30971c6 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -1452,7 +1452,7 @@ there are neither package declarations nor a C<$VERSION>. long for Perl to handle. You have to be seriously twisted to write code that triggers this error. -=item Deprecated character(s) in \\N{...} starting at '%s' +=item Deprecated character in \\N{...}; marked by <-- HERE in \\N{%s<-- HERE %s (D deprecated) Just about anything is legal for the C<...> in C<\N{...}>. But starting in 5.12, non-reasonable ones that don't look like names are diff --git a/toke.c b/toke.c index 42a80a6..5f3abe8 100644 --- a/toke.c +++ b/toke.c @@ -3264,14 +3264,11 @@ S_scan_const(pTHX_ char *start) } } if (problematic) { - char *string; - Newx(string, e - i + 1, char); - Copy(i, string, e - i, char); - string[e - i] = '\0'; + /* The e-i passed to the final %.*s makes sure that + * should the trailing NUL be missing that this + * print won't run off the end of the string */ Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), - "Deprecated character(s) in \\N{...} starting at '%s'", - string); - Safefree(string); + "Deprecated character in \\N{...}; marked by <-- HERE in \\N{%.*s<-- HERE %.*s", i - s + 1, s, e - i, i + 1); } } } /* End \N{NAME} */