$OpenBSD: patch-nsprpub_pr_src_misc_prinit_c,v 1.2 2005/12/20 23:44:00 bernd Exp $
--- nsprpub/pr/src/misc/prinit.c.orig	Wed Apr 28 02:34:07 2004
+++ nsprpub/pr/src/misc/prinit.c	Sat Sep 10 09:47:32 2005
@@ -433,6 +433,12 @@ PR_IMPLEMENT(PRStatus) PR_Cleanup()
 	    _PR_LogCleanup();
 
         /*
+         * accesses the current thread
+         */
+        _PR_CleanupNet();
+        _PR_CleanupIO();
+
+        /*
          * This part should look like the end of _PR_NativeRunThread
          * and _PR_UserRunThread.
          */
@@ -444,6 +450,7 @@ PR_IMPLEMENT(PRStatus) PR_Cleanup()
             PR_DELETE(me->stack);
             PR_DELETE(me);
         }
+        _PR_MD_SET_CURRENT_THREAD(NULL);
 
         /*
          * XXX: We are freeing the heap memory here so that Purify won't
@@ -452,8 +459,6 @@ PR_IMPLEMENT(PRStatus) PR_Cleanup()
          * Ideally, for each _PR_InitXXX(), there should be a corresponding
          * _PR_XXXCleanup() that we can call here.
          */
-        _PR_CleanupNet();
-        _PR_CleanupIO();
 #ifdef WINNT
         _PR_CleanupCPUs();
 #endif
