This bug is in the NSPR classic code base. I haven't looked at the pthread version to see if it also has this bug. In PR_Cleanup, we first set the current thread to NULL (in _PR_MD_EXIT_THREAD) and then call _PR_CleanupIO. But _PR_CleanupIO calls PR_Lock, which attaches the current thread again. Here is the stack trace: => _PRI_AttachThread(type = RW_WRITER, priority = PR_PRIORITY_NORMAL, stack = (nil), flags = 0), line 1453 in "pruthr.c"  _pr_current_thread_tls(), line 359 in "solaris.c"  PR_Lock(lock = 0x24f50), line 224 in "prulock.c"  _PR_Putfd(fd = 0x22778), line 173 in "prfdcach.c"  PR_FreeFileDesc(fd = 0x22778), line 149 in "prio.c"  _PR_CleanupIO(), line 80 in "prio.c"  PR_Cleanup(), line 453 in "prinit.c"  main(argc = 1, argv = 0xffbef90c), line 409 in "foreign.c" Seems that we need to move the _PR_MD_EXIT_THREAD call near the end of the PR_Cleanup call.
*** Bug 222709 has been marked as a duplicate of this bug. ***
PR_Cleanup must be slightly reordered: threads must be cleaned-up *AFTER* CleanupIO(), as CleanupIO() does a _pr_current_thread_tls.
Sorry for the delay. We have been successfully using the proposed patch (for NSPR version 4.3) since beginning of March.
To fix the memory leaks in PR_Cleanup, we must move the _PR_CleanupIO call before the _PR_MD_EXIT_THREAD(me) call. I moved _PR_CleanupIO (and _PR_CleanupNet) further up, before where we start to clean up the current thread. I checked in this patch (a variant of Gerard's patch) on the NSPR trunk (NSPR 4.7.1). Checking in prinit.c; /cvsroot/mozilla/nsprpub/pr/src/misc/prinit.c,v <-- prinit.c new revision: 3.49; previous revision: 3.48 done
Attachment #154971 - Attachment is obsolete: true
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.