Thank you.
-------- Original Message -------- Subject: [PATCH] libperl leaks a THREAD_KEY each time it is reloaded Date: 05 Jan 2005 03:21:06 -0800 From: Gisle Aas <[EMAIL PROTECTED]> To: [email protected]
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.
Test script to demonstrate this failure is attached.
Regards, Gisle
-- __________________________________________________________________ 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
embed.t
Description: Troff document
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
