Bug 469508: made errStrBuf thread-safe by allocating it on the stack.
authorwtc%google.com
Tue, 16 Dec 2008 00:36:56 +0000
changeset 4022 6f13e13c5559cab0b7ee5b92f6b4dd5dcaed0eb0
parent 4021 9921002395c846ccf2fa6ce7e4a2effef6296dfa
child 4023 5c30d636e388d02a69dddde56e6d9fd9fc9bb420
push idunknown
push userunknown
push dateunknown
bugs469508
Bug 469508: made errStrBuf thread-safe by allocating it on the stack. r=julien.pierre.
pr/src/linking/prlink.c
--- a/pr/src/linking/prlink.c
+++ b/pr/src/linking/prlink.c
@@ -218,41 +218,35 @@ static LoadLibraryWFn loadLibraryW = Loa
 
 #ifdef WIN32
 static int pr_ConvertUTF16toUTF8(LPCWSTR wname, LPSTR name, int len);
 #endif
 
 /************************************************************************/
 
 #if !defined(USE_DLFCN) && !defined(HAVE_STRERROR)
-static char* errStrBuf = NULL;
 #define ERR_STR_BUF_LENGTH    20
-static char* errno_string(PRIntn oserr)
-{
-    if (errStrBuf == NULL)
-        errStrBuf = PR_MALLOC(ERR_STR_BUF_LENGTH);
-    PR_snprintf(errStrBuf, ERR_STR_BUF_LENGTH, "error %d", oserr);
-    return errStrBuf;
-}
 #endif
 
 static void DLLErrorInternal(PRIntn oserr)
 /*
 ** This whole function, and most of the code in this file, are run
 ** with a big hairy lock wrapped around it. Not the best of situations,
 ** but will eventually come up with the right answer.
 */
 {
     const char *error = NULL;
 #ifdef USE_DLFCN
     error = dlerror();  /* $$$ That'll be wrong some of the time - AOF */
 #elif defined(HAVE_STRERROR)
     error = strerror(oserr);  /* this should be okay */
 #else
-    error = errno_string(oserr);
+    char errStrBuf[ERR_STR_BUF_LENGTH];
+    PR_snprintf(errStrBuf, sizeof(errStrBuf), "error %d", oserr);
+    error = errStrBuf;
 #endif
     if (NULL != error)
         PR_SetErrorText(strlen(error), error);
 }  /* DLLErrorInternal */
 
 void _PR_InitLinker(void)
 {
     PRLibrary *lm = NULL;
@@ -377,20 +371,16 @@ void _PR_ShutdownLinker(void)
     
     PR_DestroyMonitor(pr_linker_lock);
     pr_linker_lock = NULL;
 
     if (_pr_currentLibPath) {
         free(_pr_currentLibPath);
         _pr_currentLibPath = NULL;
     }
-
-#if !defined(USE_DLFCN) && !defined(HAVE_STRERROR)
-    PR_DELETE(errStrBuf);
-#endif
 }
 #endif
 
 /******************************************************************************/
 
 PR_IMPLEMENT(PRStatus) PR_SetLibraryPath(const char *path)
 {
     PRStatus rv = PR_SUCCESS;