For a threaded perl the thread key is allocated on the first call to perl_alloc() but there is nothing that frees this key on Unix. On Windows we watch for the DLL_PROCESS_DETACH event and then release the key. This patch implements the same for other platforms using compiler dependent destructors. The patch has been tested on Linux (gcc) and HP-UX (cc and gcc).
--- perl.c.orig 2005-01-01 12:56:44.000000000 -0800
+++ perl.c 2005-01-05 03:02:55.000000000 -0800
@@ -958,6 +958,31 @@
#endif
}
+#if defined(USE_5005THREADS) || defined(USE_ITHREADS)
+/* provide destructors to clean up the thread key when libperl is unloaded */
+#ifndef WIN32 /* handled during DLL_PROCESS_DETACH in win32/perllib.c */
+
+#if defined(__hpux) && !defined(__GNUC__)
+#pragma fini "perl_fini"
+#endif
+
+#if defined(__GNUC__) && defined(__attribute__) +/* want to make sure __attribute__ works here even
+ * for -Dd_attribut=undef builds.
+ */
+#undef __attribute__
+#endif
+
+static void __attribute__((destructor))
+perl_fini()
+{
+ if (PL_curinterp)
+ FREE_THREAD_KEY;
+}
+
+#endif /* WIN32 */
+#endif /* THREADS */
+
void
Perl_call_atexit(pTHX_ ATEXIT_t fn, void *ptr)
{
This patch has been applied to ActivePerl because a customer had Apache with mod_perl crash after a certain number of reloads. Perl crashes when it can't allocate a new thread key and each time Apache reloads it will dlclose() and dlopen() mod_perl.so. That patch make sure that perl's thread key get freed at dlclose() time.
I'm trying to write a workaround for this perl bug in mp2, but I constantly get a segfault:
#0 0x4050c4ad in Perl_safesysfree (where=0x936da80) at util.c:147
147 DEBUG_m( PerlIO_printf(Perl_debug_log, "0x%"UVxf": (%05ld) free\n",PTR2UV(where),(long)PL_an++));
(gdb) bt
#0 0x4050c4ad in Perl_safesysfree (where=0x936da80) at util.c:147
#1 0x4053be56 in Perl_sv_clear (my_perl=0x92bc178, sv=0x936df98) at sv.c:5231
#2 0x4053c2be in Perl_sv_free (my_perl=0x92bc178, sv=0x936df98) at sv.c:5376
#3 0x40562cc8 in Perl_free_tmps (my_perl=0x92bc178) at scope.c:196
#4 0x404ac567 in perl_destruct (my_perl=0x92bc178) at perl.c:524
#5 0x40471395 in modperl_perl_destruct (perl=0x92bc178) at modperl_perl.c:192
#6 0x4045c50b in modperl_interp_destroy (interp=0x92d2338)
at modperl_interp.c:145
I suppose this is because I call:
FREE_THREAD_KEY;
before:
perl_destruct(perl);
but if I call after I get another segfault:
#0 0x4050d919 in S_mess_alloc (my_perl=0x0) at util.c:832
832 if (!PL_dirty)
(gdb) bt
#0 0x4050d919 in S_mess_alloc (my_perl=0x0) at util.c:832
#1 0x4050dbf3 in Perl_vmess (my_perl=0x0,
pat=0x40480444 "panic: pthread_setspecific (%d) [%s:%d]", args=0xbfffefdc)
at util.c:960
#2 0x4050e459 in S_vdie_croak_common (my_perl=0x0,
pat=0x40480444 "panic: pthread_setspecific (%d) [%s:%d]", args=0xbfffefdc,
msglen=0xbfffefa8, utf8=0xbfffefa4) at util.c:1055
#3 0x4050ed19 in Perl_vcroak (my_perl=0x0,
pat=0x40480444 "panic: pthread_setspecific (%d) [%s:%d]", args=0xbfffefdc)
at util.c:1175
#4 0x4050ee80 in Perl_croak_nocontext (
pat=0x40480444 "panic: pthread_setspecific (%d) [%s:%d]") at util.c:1196
#5 0x4045c47e in modperl_interp_destroy (interp=0x91e85e0)
at modperl_interp.c:134
#6 0x4045c701 in modperl_interp_pool_destroy (data=0x91e6760)
at modperl_interp.c:201
#7 0x40299b2d in run_cleanups (cref=0x827f0d8) at apr_pools.c:1951
#8 0x40298ff2 in pool_clear_debug (pool=0x827f0c8,
What do I do? I suppose there should be some hook inside perl_destruct when this can be called.
-- __________________________________________________________________ Stas Bekman JAm_pH ------> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]