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
From:
demerphq
Date:
February 25, 2018 10:16
Subject:
Re: [perl #132892] Possibly memory leak when matching strings usingpre-compiled regexes stored in hash key (perl >= v5.26)
Message ID:
CANgJU+V823RPE-NvH-8_hNr7+detjm+yzRGG49shjHMLTcwUzQ@mail.gmail.com
On 25 February 2018 at 10:57, demerphq <demerphq@gmail.com> wrote:
> On 25 February 2018 at 10:50, demerphq <demerphq@gmail.com> wrote:
>> On 23 February 2018 at 14:03, Dave Mitchell <davem@iabyn.com> wrote:
>>> On Fri, Feb 23, 2018 at 10:34:50AM +0100, demerphq wrote:
>>>> Fixed in 910a6a8be166fb3780dcd2520e3526e537383ef2
>>>>
>>>> Unfortunately I don't know how to test for a memory leak, so no tests included.
>>>
>>> see t/op/svleak.t. It runs a bit of code several times in a loop and
>>> tests whether PL_sv_count fails to remain constant.
>>
>> Thanks, i just pushed 06f26dc89ebc43d50835aaecc477ec160a5a5835 which
>> does just that.
>>
>> FWIW, there is still an open question why this happens at all. Keys
>> should be null terminated, and we should not fall into this code-path.
>
> Apparently I am wrong:
>
> $ ./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.
>
> Another good reason not to put patterns in keys. :-(

Corroborating this I hacked a way to get an unshared hash, and then
checked what things look like, and the keys are not shared as
expected, and are null terminated.

$ ./perl -Ilib -MHash::Util=new_unshared_hash -MDevel::Peek -e'my
$hv=new_unshared_hash(); $hv->{foo}=1; Dump((keys %$hv)[0])'
SV = PV(0x2670c58) at 0x2699680
  REFCNT = 1
  FLAGS = (TEMP,POK,pPOK)
  PV = 0x269f9e8 "foo"\0
  CUR = 3
  LEN = 10

Yves

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

Thread Previous


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