Skip Menu |

This queue is for tickets about the List-MoreUtils CPAN distribution.

Report information
The Basics
Id: 66466
Status: resolved
Priority: 0/
Queue: List-MoreUtils

People
Owner: Nobody in particular
Requestors: arc [...] cpan.org
Cc:
AdminCc:

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



Subject: [PATCH] Fix memory leak in natatime()
natatime() has a bug which prevents it from ever freeing the values it returns. The attached patch fixes the bug, and includes a test which (if you have Test::LeakTrace installed) ensures that no memory is leaked. (If you don't have Test::LeakTrace installed, the memory-leak test is quietly skipped.) It should be straightforward to apply the same leak-testing approach to any other functions; since memory leaks in some functions have been a long-standing problem with List::MoreUtils, this seems valuable to me.
Subject: natatime_leak.diff
From 13ba5f11a35cdbd4094d6f2e117caebb171f6607 Mon Sep 17 00:00:00 2001 From: Aaron Crane <arc@aaroncrane.co.uk> Date: Tue, 8 Mar 2011 15:07:15 +0000 Subject: Fix memory leak in natatime() --- MoreUtils.xs | 3 +-- t/lib/Test.pm | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/MoreUtils.xs b/MoreUtils.xs index d091bf9..14d72f2 100644 --- a/MoreUtils.xs +++ b/MoreUtils.xs @@ -1089,9 +1089,8 @@ _natatime_iterator () EXTEND(SP, nret); for (i = 0; i < args->natatime; i++) { - if (args->nsvs) { + if (args->curidx < args->nsvs) { ST(i) = sv_2mortal(newSVsv(args->svs[args->curidx++])); - args->nsvs--; } else { XSRETURN(i); diff --git a/t/lib/Test.pm b/t/lib/Test.pm index 3d001f6..08f6be8 100644 --- a/t/lib/Test.pm +++ b/t/lib/Test.pm @@ -7,7 +7,7 @@ use List::MoreUtils ':all'; # Run all tests sub run { - plan tests => 154; + plan tests => 155; test_any(); test_all(); @@ -444,6 +444,14 @@ sub test_natatime { push @r, @vals; } is( arrayeq( \@r, \@a ), 1, "natatime2" ); + + leak_free_ok('natatime leaks no memory', sub { + my @y = 1; + my $it = natatime 2, @y; + while ( my @vals = $it->() ) { + # do nothing + } + }); } sub test_zip { @@ -654,4 +662,14 @@ sub arrayeq { return 1; } +sub leak_free_ok { + my $desc = shift; + my $code = shift; + SKIP: { + skip 'Test::LeakTrace not installed', 1 + unless eval { require Test::LeakTrace; 1 }; + &Test::LeakTrace::no_leaks_ok($code, $desc); + } +} + 1; -- 1.7.3.5
Hi, proving all RT's is scheduled after I finished Proc::ProcessTable rewrite. Please understand that I will try to fix as many issues as possible with one real developing action.
Subject: Re: [rt.cpan.org #66466] [PATCH] Fix memory leak in natatime()
Date: Tue, 15 Mar 2011 17:48:35 +0000
To: bug-List-MoreUtils [...] rt.cpan.org
From: Aaron Crane <arc [...] cpan.org>
Jens Rehsack via RT <bug-List-MoreUtils@rt.cpan.org> wrote: Show quoted text
> proving all RT's is scheduled after I finished Proc::ProcessTable rewrite. > Please understand that I will try to fix as many issues as possible with > one real developing action.
Hi, Jens. Don't worry, I quite understand — we all have plenty of things to occupy our time. If you'd like, I'd be happy to put some work in on producing an updated version of List::MoreUtils. Perhaps you have a public revision-control repo available somewhere? -- Aaron Crane ** http://aaroncrane.co.uk/
On Tue Mar 15 13:50:47 2011, arc@cpan.org wrote: Show quoted text
> Jens Rehsack via RT <bug-List-MoreUtils@rt.cpan.org> wrote:
> > proving all RT's is scheduled after I finished Proc::ProcessTable rewrite. > > Please understand that I will try to fix as many issues as possible with > > one real developing action.
> > Hi, Jens. Don't worry, I quite understand — we all have plenty of > things to occupy our time. > > If you'd like, I'd be happy to put some work in on producing an > updated version of List::MoreUtils.
Attractive offer - but unfortunately I'd like to invest some work first to get a picture where this module should go in future. And I would hate it to let you spend time to do work which I might throw away later. Show quoted text
> Perhaps you have a public > revision-control repo available somewhere?
One of the major todo items: setting up a (more or less) public svn server. I talked to Adam before, but I do not like his server setup for my (being responsible) modules. I hope I can get a free week in Spring to get e.g. that task done. /Jens
Subject: Re: [rt.cpan.org #66466] [PATCH] Fix memory leak in natatime()
Date: Tue, 15 Mar 2011 20:10:33 +0000
To: bug-List-MoreUtils [...] rt.cpan.org
From: Aaron Crane <arc [...] cpan.org>
Jens Rehsack via RT <bug-List-MoreUtils@rt.cpan.org> wrote: Show quoted text
> On Tue Mar 15 13:50:47 2011, arc@cpan.org wrote:
>> If you'd like, I'd be happy to put some work in on producing an >> updated version of List::MoreUtils.
> > Attractive offer - but unfortunately I'd like to invest some work first to get a picture > where this module should go in future. And I would hate it to let you spend time to do > work which I might throw away later.
How about a bugfix-only release? There are several open RT bugs, and it seems to me that issuing a release with fixes for memory leaks and the like would be valuable to people and projects with a dependency on List::MoreUtils. Show quoted text
>> Perhaps you have a public >> revision-control repo available somewhere?
> > One of the major todo items: setting up a (more or less) public svn server. I talked to > Adam before, but I do not like his server setup for my (being responsible) modules. > > I hope I can get a free week in Spring to get e.g. that task done.
I'd be happy to maintain a series of patches against the current 0.30 release (in the form of a Git repo) until you have time to set up a public svn server, if that would help. -- Aaron Crane ** http://aaroncrane.co.uk/
Subject: Re: [rt.cpan.org #66466] [PATCH] Fix memory leak in natatime()
Date: Wed, 16 Mar 2011 12:31:11 +1100
To: bug-List-MoreUtils [...] rt.cpan.org
From: Adam Kennedy <adamkennedybackup [...] gmail.com>
Until Jens is ready, I'm happy to give you commit to the public repository where my release series is being generated from at http://svn.ali.as/cpan/trunk/List-MoreUtils Do you have a CPAN id? Or if not, a prefered email address. Adam K On 16 March 2011 06:10, Jens Rehsack via RT <bug-List-MoreUtils@rt.cpan.org> wrote: Show quoted text
>       Queue: List-MoreUtils >  Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=66466 > > > On Tue Mar 15 13:50:47 2011, arc@cpan.org wrote:
>> Jens Rehsack via RT <bug-List-MoreUtils@rt.cpan.org> wrote:
>> > proving all RT's is scheduled after I finished Proc::ProcessTable rewrite. >> > Please understand that I will try to fix as many issues as possible with >> > one real developing action.
>> >> Hi, Jens.  Don't worry, I quite understand — we all have plenty of >> things to occupy our time. >> >> If you'd like, I'd be happy to put some work in on producing an >> updated version of List::MoreUtils.
> > Attractive offer - but unfortunately I'd like to invest some work first to get a picture > where this module should go in future. And I would hate it to let you spend time to do > work which I might throw away later. >
>>  Perhaps you have a public >> revision-control repo available somewhere?
> > One of the major todo items: setting up a (more or less) public svn server. I talked to > Adam before, but I do not like his server setup for my (being responsible) modules. > > I hope I can get a free week in Spring to get e.g. that task done. > > /Jens >
Subject: Re: [rt.cpan.org #66466] [PATCH] Fix memory leak in natatime()
Date: Wed, 16 Mar 2011 01:41:57 +0000
To: bug-List-MoreUtils [...] rt.cpan.org
From: Aaron Crane <arc [...] cpan.org>
Reserved Local Account via RT <bug-List-MoreUtils@rt.cpan.org> wrote: Show quoted text
> Until Jens is ready, I'm happy to give you commit to the public > repository where my release series is being generated from at > http://svn.ali.as/cpan/trunk/List-MoreUtils > > Do you have a CPAN id? Or if not, a prefered email address.
Thanks, Adam, that would be great. My CPAN id is arc. -- Aaron Crane ** http://aaroncrane.co.uk/