[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]
Re: [perl #59516] Memory leak with regex in 5.10.0
On 2008-10-04, at 15:02:32 +0100, Dave Mitchell wrote:
> On Sat, Oct 04, 2008 at 02:51:09PM +0100, Nicholas Clark wrote:
> > On Sat, Oct 04, 2008 at 12:55:04PM +0100, Dave Mitchell wrote:
> >
> > > The leak appears to be somewhere in the compilation of character classes.
> > > The following code leaks like a sieve on 5.10.0 and bleed, but not 5.8.8:
> > >
> > > while (1) {
> > > qr/[a]/;
> > > }
> >
> > Are you sure that it's character classes?
> >
> > ./perl -le 'while (1) { qr// }'
> >
> > merrily chews through memory like it's going out of fashion. However, all
> > memory is freed at the end of the program:
>
> Hmm, maybe I reduced the original code too much, and threw out the
> original bug but gained a new one.
>
>
> This doesn't leak:
>
> my $n = 1;
> while (1) {
> $n = 1 - $n;
> "abc" =~ /$n/;
> }
>
> This does:
>
> my $n = 1;
> while (1) {
> $n = 1 - $n;
> "abc" =~ /[a]${n}/;
> }
>
> (The non-constant $n is to defeat regex compilation caching).
Fixed with the following change:
Change 34507 by mhx@mhx-r2d2 on 2008/10/18 18:11:57
Fix memory leak in // caused by single-char character class
optimization. This was most probably introduced with #28262.
This change fixes perl #59516.
Affected files ...
... //depot/perl/regcomp.c#660 edit
Differences ...
==== //depot/perl/regcomp.c#660 (text) ====
@@ -8350,6 +8350,9 @@
*STRING(ret)= (char)value;
STR_LEN(ret)= 1;
RExC_emit += STR_SZ(1);
+ if (listsv) {
+ SvREFCNT_dec(listsv);
+ }
return ret;
}
/* optimize case-insensitive simple patterns (e.g. /[a-z]/i) */
--
Langsam's Laws:
(1) Everything depends.
(2) Nothing is always.
(3) Everything is sometimes.
signature.asc
- References to:
-
"robin.hill@biowisdom.com (via RT)" <perlbug-followup@perl.org>
Dave Mitchell <davem@iabyn.com>
Nicholas Clark <nick@ccl4.org>
Dave Mitchell <davem@iabyn.com>
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]