This queue is for tickets about the BSD-Resource CPAN distribution.

Report information
The Basics
Id:
53856
Status:
resolved
Priority:
Low/Low
Queue:

People
Owner:
Nobody in particular
Requestors:
user42 [...] zip.com.au
Cc:
AdminCc:

BugTracker
Severity:
(no value)
Broken in:
(no value)
Fixed in:
(no value)



Subject: memory leak in get_rlimits()
Date: Thu, 21 Jan 2010 08:14:51 +1100
To: bug-BSD-Resource@rt.cpan.org
From: Kevin Ryde <user42@zip.com.au>
With recent debian i386 packaged perl 5.10.1 and BSD::Resource 1.2903, the program rlimits.pl below consumes ever more memory, where I expected it to remain constant. I think the newHV() in _get_rlimits() is leaking due to a ref count too far. Looks like the HV* typemap return is meant to be used with a mortalize at the point of creation, per diff below. POSIX.xs localeconv() does this, and had a similar leak up until 5.8.4 or thereabouts. (An immediate mortalize has the happy effect of protecting against a leak if the filling code croaks for some reason, though that wouldn't occur in _get_rlimits().) Ditto the undocumented get_prios() I think, per prios.pl below growing ever bigger too ...
use strict; use warnings; use BSD::Resource; for (;;) { BSD::Resource::get_rlimits(); }
use strict; use warnings; use BSD::Resource; for (;;) { BSD::Resource::get_prios(); }
--- Resource.xs.orig 2010-01-19 17:00:36.000000000 +1100 +++ Resource.xs 2010-01-19 17:02:23.000000000 +1100 @@ -658,6 +658,7 @@ _get_rlimits() CODE: RETVAL = newHV(); + sv_2mortal((SV*)RETVAL); #if defined(RLIMIT_AIO_MEM) || defined(HAS_RLIMIT_AIO_MEM) hv_store(RETVAL, "RLIMIT_AIO_MEM" , 14, newSViv(RLIMIT_AIO_MEM), 0); #endif @@ -716,6 +717,7 @@ _get_prios() CODE: RETVAL = newHV(); + sv_2mortal((SV*)RETVAL); #if defined(PRIO_PROCESS) hv_store(RETVAL, "PRIO_PROCESS", 12, newSViv(PRIO_PROCESS), 0); #endif
Thanks, the fix will be in the next release.


This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.