perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexander Bergolth <>
Subject Re: mod_perl2 (ModPerl::Registry) crashes httpd if request-object is used in a subroutine
Date Thu, 08 Jan 2004 20:43:31 GMT
On 01/08/04 19:15, Perrin Harkins wrote:
> Alexander Bergolth wrote:
>> When I'm using the request-object in a subroutine without having passed
>> it to the sub as a parameter, the apache child processes die with a 
>> segmentation fault when being reused.
> Well, it probably shouldn't segfault, but you can't do that.  You are 
> creating a closure which will permanently keep a copy of the very first 
> $r that existed in that process, but $r is really an apache structure 
> that gets freed after each request.  If you need a copy of $r but don't 
> want to pass it, and you are running in pre-fork MPM, you can use the 
> Apache->request() call.

Why do I create a closure? If i'd create a closure I would have to store 
a reference to an _anonymous sub, something like that:

---------- snipp! ----------
my $r = shift;

my $printline3 = sub {

&$printline3("Uses frozen request variable.");
---------- snipp! ----------
( See )

My version uses a regular (named-) sub and the scope of the variable $r 
should be lexically local to the enclosing block. So the value of $r 
should be the same as in the "main" block, where it is assigned via
"$r = shift;" at every new request. (I've again attached my version 
below for the sake of completeness.)

Moreover I've read that Apache->request should be avoided in mod_perl2:

---------- snipp! ----------

use strict;

my $r = shift;
$r->print( "<html>\n"
           ."<body>\n" );

&printline1($r, "This works");
&printline2("This crashes the httpd process when it is reused");

$r->print( "</body>\n"
           ."</html>\n" );

sub printline1 {
   my $r = shift;

sub printline2 {

---------- snipp! ----------

Alexander (Leo) Bergolth                
WU-Wien - Zentrum fuer Informatikdienste
                  Computers are like air conditioners -
            they stop working properly when you open Windows

Reporting bugs:
Mail list info:

View raw message