develooper Front page | perl.perl5.porters | Postings from February 2018

Re: [perl #132892] Possibly memory leak when matching strings usingpre-compiled regexes stored in hash key (perl >= v5.26)

Thread Previous | Thread Next
From:
demerphq
Date:
February 25, 2018 10:57
Subject:
Re: [perl #132892] Possibly memory leak when matching strings usingpre-compiled regexes stored in hash key (perl >= v5.26)
Message ID:
CANgJU+W5v=zf3YoLFpXEDu6KiX4YYN=MX0cywk1+AV==Wyej8g@mail.gmail.com
On 25 February 2018 at 11:19, Sergey Aleynikov via RT
<perlbug-followup@perl.org> wrote:
> On Sun, 25 Feb 2018 01:58:15 -0800, demerphq wrote:
>
>> $ ./perl -Ilib -MDevel::Peek -le'%h=("^foo"=>1); my ($re)=keys %h;
>> Dump $re'
>> SV = PV(0x1009d08) at 0x103f0b8
>>   REFCNT = 1
>>   FLAGS = (POK,IsCOW,pPOK)
>>   PV = 0x1041478 "^foo"
>>   CUR = 4
>>   LEN = 0
>>
>> This appears to be a side-effect of shared keys.
>
>
> But the failed check in regcomp.c is not *(SvEND(msv)) == 0, but rather SvLEN(msv) > SvCUR(msv). But doesn't line 3134 in hv.c (HEK_KEY(hek)[len] = 0;) guarantee that it's implicitly null-terminated, just not shown by Devel::Peek as such?

That sounds correct, but i dont think the regex engine has any way to
know that this LEN=0 case comes from a key. Since we don't know the
len we cant safely check past CUR.

Yves


-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

Thread Previous | 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