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 {
  $r->print($_[0]."<br>\n");
}

&$printline3("Uses frozen request variable.");
---------- snipp! ----------
( See http://www.perldoc.com/perl5.6/pod/perlref.html#4. )

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:
http://perl.apache.org/docs/2.0/user/porting/compat.html#C_Apache_E_gt_request_

---------- snipp! ----------
#!/usr/bin/perl

use strict;

my $r = shift;
$r->content_type("text/html");
$r->print( "<html>\n"
          ."<head><title>Testpage</title></head>\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;
  $r->print($_[0]."<br>\n");
}

sub printline2 {
  $r->print($_[0]."<br>\n");
}

1;
---------- snipp! ----------

Cheers,
--leo
--
-----------------------------------------------------------------------
Alexander (Leo) Bergolth                          [EMAIL PROTECTED]
WU-Wien - Zentrum fuer Informatikdienste       http://leo.wu-wien.ac.at
                 Computers are like air conditioners -
           they stop working properly when you open Windows


-- Reporting bugs: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html



Reply via email to