$OpenBSD: patch-nsprpub_pr_src_misc_prinit_c,v 1.1.1.1 2004/02/15 19:37:25 wilfried Exp $
--- nsprpub/pr/src/misc/prinit.c.orig	2003-01-20 21:13:09.000000000 +0100
+++ nsprpub/pr/src/misc/prinit.c	2003-12-12 12:41:30.000000000 +0100
@@ -430,6 +430,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.
          */
@@ -441,6 +447,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
@@ -449,8 +456,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
