From: Christian Walde Date: Mon, 7 Jul 2014 16:39:33 +0000 (+0200) Subject: fix a memory leak introduced by 1f8cad5e5a1875de94d63ac91d8ded4d2282c62e X-Git-Tag: v0.025~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FWeb-Simple.git;a=commitdiff_plain;h=1f727762b7d2af3c22ae86a9c9012154a82b1457;hp=90217864440f3ffadbbeaa12dbb76686dffadefd fix a memory leak introduced by 1f8cad5e5a1875de94d63ac91d8ded4d2282c62e --- diff --git a/Changes b/Changes index 54613fe..8dc6a01 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for Web-Simple + - fixes a memory leak that occurs when calling + Web::Simple::Application::to_psgi_app + 0.024 - 2014-07-03 - small documentation fixes diff --git a/lib/Web/Dispatch.pm b/lib/Web/Dispatch.pm index 2a5a835..d34fe6e 100644 --- a/lib/Web/Dispatch.pm +++ b/lib/Web/Dispatch.pm @@ -14,7 +14,7 @@ with 'Web::Dispatch::ToApp'; has dispatch_app => ( is => 'lazy', builder => sub { shift->dispatch_object->to_app } ); -has dispatch_object => (is => 'ro', required => 0); +has dispatch_object => (is => 'ro', required => 0, weak_ref => 1); has parser_class => ( is => 'ro', default => quote_sub q{ 'Web::Dispatch::Parser' } ); diff --git a/t/dispatch_misc.t b/t/dispatch_misc.t index 05bdd67..842cf52 100644 --- a/t/dispatch_misc.t +++ b/t/dispatch_misc.t @@ -64,7 +64,8 @@ sub app_is_object { sub to_app { [ 999, [], ["ok"] ] } } - my $d = Web::Dispatch->new( dispatch_object => ObjectApp->new ); + my $o = ObjectApp->new; + my $d = Web::Dispatch->new( dispatch_object => $o ); my $res = $d->call; cmp_ok $res->[0], '==', 999, "Web::Dispatch can dispatch properly, given only an object with to_app method"; diff --git a/t/leak.t b/t/leak.t new file mode 100644 index 0000000..2f16e1b --- /dev/null +++ b/t/leak.t @@ -0,0 +1,15 @@ +use strictures; +use Test::More eval { require Devel::Cycle } ? 'no_plan' : ( skip_all => 'No Devel::Cycle' ); + +use Web::Simple; +use Devel::Cycle; + +my $counter; +my $on_cycle = sub { Devel::Cycle::_do_report( ++$counter, shift ) }; +{ + local *STDOUT = *STDERR; + Devel::Cycle::find_cycle( main->new->to_psgi_app, $on_cycle ); +} +ok !$counter, "no leak in to_psgi_app"; + +done_testing;