This just exposes an already known problem.

my $pool;
sub handler {
  my $r = shift;
  $pool = $r->pool;
}

In this case, by the time $pool->DESTROY() gets called, the request pool
has already been destroyed by apache, so we have a APR::Pool object that
points to a freed pool, and thus we segfault.

Attached is a simplistic test to expose this bug. I am looking into a fix.



Stas Bekman wrote:
Got a core when running the test suite on the static server (probably at the server shutdown). couldn't reproduce it with (t/SMOKE -bug).

#0 0x4043d67f in find_entry (ht=0x6c2f742f, key=0x407538e6, klen=14, val=0x0)
at apr_hash.c:235
235 for (hep = &ht->array[hash & ht->max], he = *hep;
(gdb) bt
#0 0x4043d67f in find_entry (ht=0x6c2f742f, key=0x407538e6, klen=14, val=0x0)
at apr_hash.c:235
#1 0x4043d8a9 in apr_hash_get (ht=0x6c2f742f, key=0x407538e6, klen=-1)
at apr_hash.c:297
#2 0x4044f5fd in apr_pool_userdata_get (data=0xbfffe8c8,
key=0x407538e6 "APR::Pool::new", pool=0x81140f8) at apr_pools.c:1851
#3 0x40752173 in mpxs_apr_pool_DESTROY (my_perl=0x869f408, obj=0x944da84)
at APR__Pool.h:352
#4 0x407533b2 in XS_APR__Pool_DESTROY (my_perl=0x869f408, cv=0x8af8c94)
at Pool.xs:119
#5 0x400bdbba in Perl_pp_entersub (my_perl=0x869f408) at pp_hot.c:2857
#6 0x4003ec29 in S_call_body (my_perl=0x869f408, myop=0xbfffeaf0, is_eval=0)
at perl.c:2285
#7 0x4003e775 in Perl_call_sv (my_perl=0x869f408, sv=0x8af8c94, flags=150)
at perl.c:2206
#8 0x400c9f0b in Perl_sv_clear (my_perl=0x869f408, sv=0x944dac0) at sv.c:5125
#9 0x400ca8c8 in Perl_sv_free (my_perl=0x869f408, sv=0x944dac0) at sv.c:5371
#10 0x400ca434 in Perl_sv_clear (my_perl=0x869f408, sv=0x944dacc) at sv.c:5223
#11 0x400ca8c8 in Perl_sv_free (my_perl=0x869f408, sv=0x944dacc) at sv.c:5371
#12 0x400ad520 in Perl_hv_free_ent (my_perl=0x869f408, hv=0x94500e4,
entry=0x94432b4) at hv.c:1399
---Type <return> to continue, or q <return> to quit---
#13 0x400adabe in S_hfreeentries (my_perl=0x869f408, hv=0x94500e4) at hv.c:1575
#14 0x400adb3f in Perl_hv_undef (my_perl=0x869f408, hv=0x94500e4) at hv.c:1602
#15 0x400ca30a in Perl_sv_clear (my_perl=0x869f408, sv=0x94500e4) at sv.c:5188
#16 0x400ca8c8 in Perl_sv_free (my_perl=0x869f408, sv=0x94500e4) at sv.c:5371
#17 0x400ca434 in Perl_sv_clear (my_perl=0x869f408, sv=0x94500d8) at sv.c:5223
#18 0x400ca8c8 in Perl_sv_free (my_perl=0x869f408, sv=0x94500d8) at sv.c:5371
#19 0x400ad520 in Perl_hv_free_ent (my_perl=0x869f408, hv=0x945000c,
entry=0x94431f4) at hv.c:1399
#20 0x400adabe in S_hfreeentries (my_perl=0x869f408, hv=0x945000c) at hv.c:1575
#21 0x400adb3f in Perl_hv_undef (my_perl=0x869f408, hv=0x945000c) at hv.c:1602
#22 0x400ca30a in Perl_sv_clear (my_perl=0x869f408, sv=0x945000c) at sv.c:5188
#23 0x400ca8c8 in Perl_sv_free (my_perl=0x869f408, sv=0x945000c) at sv.c:5371
#24 0x400ca434 in Perl_sv_clear (my_perl=0x869f408, sv=0x9450018) at sv.c:5223
#25 0x400ca8c8 in Perl_sv_free (my_perl=0x869f408, sv=0x9450018) at sv.c:5371
#26 0x080844ef in modperl_svptr_table_destroy (my_perl=0x869f408, tbl=0x8ad2a40)
at modperl_svptr_table.c:123
#27 0x080808e8 in modperl_perl_destruct (perl=0x869f408) at modperl_perl.c:153


#28 0x0806ebb8 in modperl_interp_destroy (interp=0x8760150)
     at modperl_interp.c:145
#29 0x0806ed61 in modperl_interp_pool_destroy (data=0x935c058)
     at modperl_interp.c:201
---Type <return> to continue, or q <return> to quit---
#30 0x4044f77e in run_cleanups (cref=0x8d38178) at apr_pools.c:1951
#31 0x4044ed05 in apr_pool_destroy (pool=0x8d38168) at apr_pools.c:730
#32 0x4044ecf1 in apr_pool_destroy (pool=0x81000a8) at apr_pools.c:727
#33 0x4044ecf1 in apr_pool_destroy (pool=0x80fe0a0) at apr_pools.c:727
#34 0x080b7165 in destroy_and_exit_process (process=0x80fe120,
     process_exit_value=0) at main.c:208
#35 0x080b7e28 in main (argc=9, argv=0xbffff134) at main.c:626



-- -------------------------------------------------------------------------------- Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5 http://gozer.ectoplasm.org/ F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5
Index: t/apr/pool_lifetime.t
===================================================================
RCS file: t/apr/pool_lifetime.t
diff -N t/apr/pool_lifetime.t
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ t/apr/pool_lifetime.t	23 Sep 2004 19:24:01 -0000
@@ -0,0 +1,60 @@
+use strict;
+use warnings FATAL => 'all';
+
+use Apache::Test;
+use Apache::TestUtil;
+use Apache::TestRequest;
+use File::Spec::Functions qw(catfile);
+
+plan tests => 2;
+
+my $module   = 'TestAPR::pool_lifetime';
+my $location = '/' . Apache::TestRequest::module2path($module);
+
+t_debug "getting the same interp ID for $location";
+my $same_interp = Apache::TestRequest::same_interp_tie($location);
+
+my $skip = $same_interp ? 0 : 1;
+
+for (1..2) {
+    my $expected = "Pong";
+    my $received = get_body($same_interp, \&GET, $location);
+    $skip++ unless defined $received;
+    skip_not_same_interp(
+        $skip,
+        $expected,
+        $received,
+        "Pong"
+    );
+}
+
+# if we fail to find the same interpreter, return undef (this is not
+# an error)
+sub get_body {
+    my $res = eval {
+        Apache::TestRequest::same_interp_do(@_);
+    };
+    return undef if $@ =~ /unable to find interp/;
+    return $res->content if $res;
+    die $@ if $@;
+}
+
+# make the tests resistant to a failure of finding the same perl
+# interpreter, which happens randomly and not an error.
+# the first argument is used to decide whether to skip the sub-test,
+# the rest of the arguments are passed to 'ok t_cmp';
+sub skip_not_same_interp {
+    my $skip_cond = shift;
+    if ($skip_cond) {
+        skip "Skip couldn't find the same interpreter", 0;
+    }
+    else {
+        my($package, $filename, $line) = caller;
+        # trick ok() into reporting the caller filename/line when a
+        # sub-test fails in sok()
+        return eval <<EOE;
+#line $line $filename
+    ok &t_cmp;
+EOE
+    }
+}
Index: t/response/TestAPR/pool_lifetime.pm
===================================================================
RCS file: t/response/TestAPR/pool_lifetime.pm
diff -N t/response/TestAPR/pool_lifetime.pm
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ t/response/TestAPR/pool_lifetime.pm	23 Sep 2004 19:24:01 -0000
@@ -0,0 +1,28 @@
+package TestAPR::pool_lifetime;
+
+use strict;
+use warnings FATAL => 'all';
+
+use Apache::Test;
+use Apache::TestUtil;
+use Apache::TestTrace;
+
+use Apache::RequestRec ();
+use APR::Pool ();
+
+use Apache::Const -compile => 'OK';
+
+my $pool;
+sub handler {
+    my $r = shift;
+    
+    $r->print("Pong");
+    $pool = $r->pool;
+    
+    Apache::OK;   
+}
+
+1;
+__END__
+
+PerlFixupHandler Apache::TestHandler::same_interp_fixup

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to