$OpenBSD: patch-mozilla_nsprpub_pr_src_misc_prinit_c,v 1.3 2007/03/01 22:37:48 robert Exp $
--- mozilla/nsprpub/pr/src/misc/prinit.c.orig	Fri Dec  1 02:34:11 2006
+++ mozilla/nsprpub/pr/src/misc/prinit.c	Wed Feb  7 13:14:08 2007
@@ -435,6 +435,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.
          */
@@ -446,6 +452,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
@@ -454,8 +461,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
