perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <>
Subject [Fwd: [PATCH] libperl leaks a THREAD_KEY each time it is reloaded]
Date Wed, 05 Jan 2005 16:57:58 GMT
Gisle, could you please provide us some more details about the crash? I'd 
like to write a test for it. I suppose you had it with mp2 worker mpm? 
Care to post the output of t/REPORT (in the mp2 source) or mp2bug? Thanks 
a lot!

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 <>

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 @@

+#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"
+#if defined(__GNUC__) && defined(__attribute__)
+/* want to make sure __attribute__ works here even
+ * for -Dd_attribut=undef builds.
+ */
+#undef __attribute__
+static void __attribute__((destructor))
+    if (PL_curinterp)
+#endif /* WIN32 */
+#endif /* THREADS */
  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()  That patch make
sure that perl's thread key get freed at dlclose() time.

Test script to demonstrate this failure is attached.


Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker     mod_perl Guide --->

View raw message