Bug 831793: PR_UnloadLibrary should consistently hold pr_linker_lock when
authorwtc%google.com
Tue, 29 Jan 2013 22:06:49 +0000
changeset 4433 c1d9877cfacfa13b0f3b952bfd04f21b42ccaf24
parent 4432 0aa876dbba108a16b51c4ba8c99fe55ec2068073
child 4434 4e7f4c6f1b1ba1fd11c7ff39446004ed7e1e5b7f
push idunknown
push userunknown
push dateunknown
bugs831793
Bug 831793: PR_UnloadLibrary should consistently hold pr_linker_lock when accessing lib->refCount. The patch is contributed by Julian Seward <jseward@acm.org>. r=wtc.
pr/src/linking/prlink.c
--- a/pr/src/linking/prlink.c
+++ b/pr/src/linking/prlink.c
@@ -954,22 +954,29 @@ pr_LoadLibraryByPathname(const char *nam
 ** Unload a shared library which was loaded via PR_LoadLibrary
 */
 PR_IMPLEMENT(PRStatus) 
 PR_UnloadLibrary(PRLibrary *lib)
 {
     int result = 0;
     PRStatus status = PR_SUCCESS;
 
-    if ((lib == 0) || (lib->refCount <= 0)) {
+    if (lib == 0) {
         PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
         return PR_FAILURE;
     }
 
     PR_EnterMonitor(pr_linker_lock);
+
+    if (lib->refCount <= 0) {
+        PR_ExitMonitor(pr_linker_lock);
+        PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+        return PR_FAILURE;
+    }
+
     if (--lib->refCount > 0) {
     PR_LOG(_pr_linker_lm, PR_LOG_MIN,
            ("%s decr => %d",
         lib->name, lib->refCount));
     goto done;
     }
 
 #ifdef XP_BEOS