Skip to content

Commit

Permalink
FIX for Apache2/mod_perl (memory leak between requests)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexis Sukrieh committed Jan 22, 2010
1 parent c6f2ccd commit aec6a47
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 4 additions & 1 deletion lib/Dancer/Handler.pm
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ sub handle_request {
# we don't want to remain like that after this point.
$request = Dancer::Request->normalize($request);

# clean the request singleton first
Dancer::SharedData->reset_all();

# initialize the request singleton
Dancer::SharedData->request($request);
Dancer::Logger->debug("[dancer.core] handle_request ".$request->path);

# read cookies from client
Dancer::Cookies->init;
Expand Down
12 changes: 7 additions & 5 deletions lib/Dancer/Route.pm
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ sub build_params {
}

# Recursive call of actions through the matching tree
# FIXME : too many reset_all() around, we need a wrapper to
# call that method and making sure we do reset the shared data first
sub call($$) {
my ($class, $handler) = @_;

Expand All @@ -212,19 +214,21 @@ sub call($$) {
# Halt: just stall everything and return the Response singleton
# useful for the redirect helper
if(Dancer::Exception::Halt->caught) {
Dancer::SharedData->reset_all();
return Dancer::Response->current;
} elsif
# Pass: pass to the next route if available. otherwise, 404.
(Dancer::Exception::Pass->caught) {
if ($handler->{'next'}) {
Dancer::SharedData->reset_all();
return Dancer::Route->call($handler->{'next'});
}
else {
Dancer::SharedData->reset_all();
my $error = Dancer::Error->new(code => 404,
message => "<h2>Route Resolution Failed</h2>"
. "<p>Last matching route passed, "
. "but no other route left.</p>");
Dancer::SharedData->reset_all();
return $error->render;
}
# no exceptions? continue the old way, although this
Expand All @@ -233,9 +237,6 @@ sub call($$) {
} else {
# trap errors
if ( $@ || (setting('warnings') && $warning)) {

Dancer::SharedData->reset_all();

my $error;
if ($@) {
$error = Dancer::Error->new(code => 500,
Expand All @@ -251,6 +252,7 @@ sub call($$) {
message => $warning);

}
Dancer::SharedData->reset_all();
return $error->render;
}

Expand All @@ -261,8 +263,8 @@ sub call($$) {
my $ct = $response->{content_type} || setting('content_type');
my $st = $response->{status} || 200;

Dancer::SharedData->reset_all();

Dancer::SharedData->reset_all();
return $content if ref($content) eq 'Dancer::Response';
return Dancer::Response->new(
status => $st,
Expand Down

0 comments on commit aec6a47

Please sign in to comment.