Skip Menu |

This queue is for tickets about the JavaScript-V8 CPAN distribution.

Report information
The Basics
Id: 122058
Status: resolved
Priority: 0/
Queue: JavaScript-V8

People
Owner: Nobody in particular
Requestors: elod.news [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Memory leaks when returning arrays or hashes from JS
Date: Fri, 9 Jun 2017 18:51:11 +0100
To: bug-JavaScript-V8 [...] rt.cpan.org
From: Elod Csirmaz <elod.news [...] gmail.com>
Broken in: 0.7.0 The following test script shows that JavaScript::V8 leaks memory when returning arrays or hashes from JS: use strict; use JavaScript::V8; use Devel::Leak; my $C = JavaScript::V8::Context->new(); $C->eval("function myf(){ return []; }"); my $handle; my $count = Devel::Leak::NoteSV($handle); for( my $i = 0; $i < 1; $i++ ) { my $r = $C->eval("myf()"); } Devel::Leak::CheckSV($handle); After a lot of hacking, removing the two lines below from V8Context.cpp appears to solve the problem: SV* V8Context::array2sv(Handle<Array> array, SvMap& seen) { AV *av = newAV(); SV *rv = newRV_noinc((SV*)av); // SvREFCNT_inc(rv); // including this leads to memory leaks ... SV * V8Context::object2sv(Handle<Object> obj, SvMap& seen) { if (enable_blessing && obj->Has(String::New("__perlPackage"))) { return object2blessed(obj); } HV *hv = newHV(); SV *rv = newRV_noinc((SV*)hv); // SvREFCNT_inc(rv); // including this leads to memory leaks It's unclear why the code needed to increase the refcounts in these cases. I see that the code calls sv_2mortal() on the return values later, but I think the increase is still not needed. Any advice on whether this is the right fix would be much appreciated.
Subject: Re: [rt.cpan.org #122058] AutoReply: Memory leaks when returning arrays or hashes from JS
Date: Fri, 9 Jun 2017 18:59:45 +0100
To: bug-JavaScript-V8 [...] rt.cpan.org
From: Elod Csirmaz <elod.news [...] gmail.com>
The output of the test script above is: new 0x8811770 : SV = IV(0x881176c) at 0x8811770 REFCNT = 1 FLAGS = (ROK) RV = 0x87f6a3c SV = PVAV(0x87f8784) at 0x87f6a3c REFCNT = 1 FLAGS = () ARRAY = 0x0 FILL = -1 MAX = -1 ARYLEN = 0x0 FLAGS = (REAL) new 0x87f6a3c : SV = PVAV(0x87f8784) at 0x87f6a3c REFCNT = 1 FLAGS = () ARRAY = 0x0 FILL = -1 MAX = -1 ARYLEN = 0x0 FLAGS = (REAL) Thanks!
This works great, thanks!