develooper Front page | perl.perl5.porters | Postings from September 2019

[perl #134390] Matching fancy Unicode regex against an ASCII stringleaks memory

Thread Next
From:
Tony Cook via RT
Date:
September 2, 2019 23:37
Subject:
[perl #134390] Matching fancy Unicode regex against an ASCII stringleaks memory
Message ID:
rt-4.0.24-24267-1567467427-302.134390-15-0@perl.org
On Sun, 01 Sep 2019 22:38:31 -0700, tonyc wrote:
> On Fri, 30 Aug 2019 08:35:45 -0700, khw wrote:
> > What is happening here is that in re_intuit_start() at line 922 in
> > regexec.c, it determines there is no possible match because you need
> > the target string to be in UTF-8 to match the character in the
> > pattern.  But something is not returning memory when re_intuit_start
> > returns failure.  There are other instances of this failure return in
> > re_intuit_start, and I suspect they leak as well.
> >
> > I'm thinking someone who knows about the regex memory allocation can
> > answer this without much effort, so I'm deferring to someone like
> > that
> > to step forward
> 
> It was fairly simple, I ran:
> 
> valgrind --leak-check=full --show-leak-kinds=all ./perl -Ilib -e '"a"
> =~ /\N{U+2129}/ for 1 .. 1000' 2>&1 | less
> 
> The leak with 1000 entries:
> 
> ==25945== 10,000 bytes in 1,000 blocks are still reachable in loss
> record 227 of 230
> ==25945==    at 0x4C2BBAF: malloc (in
> /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==25945==    by 0x2A921D: Perl_safesysmalloc (util.c:155)
> ==25945==    by 0x321DFC: Perl_sv_grow (sv.c:1599)
> ==25945==    by 0x340BF0: Perl_sv_setsv_flags (sv.c:4712)
> ==25945==    by 0x362331: Perl_newSVsv_flags (sv.c:9800)
> ==25945==    by 0x465E41: S_to_byte_substr (regexec.c:10406)
> ==25945==    by 0x436D53: Perl_re_intuit_start (regexec.c:921)
> ==25945==    by 0x446B74: Perl_regexec_flags (regexec.c:3348)
> ==25945==    by 0x306505: Perl_pp_match (pp_hot.c:3014)
> ==25945==    by 0x2A78F5: Perl_runops_debug (dump.c:2557)
> ==25945==    by 0x185946: S_run_body (perl.c:2712)
> ==25945==    by 0x184EC4: perl_run (perl.c:2635)
>  ==25945==
> 
> Fix attached.
> 
> Tony

Applied as 05a03c0da6f3694904885fa1629a6e35e75d2875.

Tony


---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=134390

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About