]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 343166: $template->process leaks 512K of RAM per call under mod_perl
authormkanat%bugzilla.org <>
Sat, 1 Jul 2006 23:10:14 +0000 (23:10 +0000)
committermkanat%bugzilla.org <>
Sat, 1 Jul 2006 23:10:14 +0000 (23:10 +0000)
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=justdave, a=justdave

Bugzilla.pm

index 91e6b00d39dcaf187af1c050bc9d77fb9b5e9c1e..0d6e6af7da87034c5af8f902746155aa667ff83c 100644 (file)
@@ -300,7 +300,21 @@ sub custom_field_names {
 sub request_cache {
     if ($ENV{MOD_PERL}) {
         require Apache2::RequestUtil;
-        return Apache2::RequestUtil->request->pnotes();
+        my $request = Apache2::RequestUtil->request;
+        my $cache = $request->pnotes();
+        # Sometimes mod_perl doesn't properly call DESTROY on all
+        # the objects in pnotes(), so we register a cleanup handler
+        # to make sure that this happens.
+        if (!$cache->{cleanup_registered}) {
+             $request->push_handlers(PerlCleanupHandler => sub {
+                 my $r = shift;
+                 foreach my $key (keys %{$r->pnotes}) {
+                     delete $r->pnotes->{$key};
+                 }
+             });
+             $cache->{cleanup_registered} = 1;
+        }
+        return $cache;
     }
     return $_request_cache;
 }