Fix for bug 154023. Initialize library refcounts properly. r=sfraser. CHIMERA_M1_0_1_BRANCH CAMINO_0_7_RELEASE CHIMERA_0_6_RELEASE
authorbnesse%netscape.com
Wed, 02 Oct 2002 20:04:47 +0000
branchCHIMERA_M1_0_1_BRANCH
changeset 2554 5fc756d0b43139e689efc3e2f95eb5935ce1caba
parent 2539 a2f434a232415c9770deff38a5272367e5ea6448
push idunknown
push userunknown
push dateunknown
reviewerssfraser
bugs154023
Fix for bug 154023. Initialize library refcounts properly. r=sfraser.
pr/src/linking/prlink.c
--- a/pr/src/linking/prlink.c
+++ b/pr/src/linking/prlink.c
@@ -236,18 +236,20 @@ void _PR_InitLinker(void)
 #ifdef USE_DLFCN
     h = dlopen(0, RTLD_LAZY);
     if (!h) {
         char *error;
         
         DLLErrorInternal(_MD_ERRNO());
         error = (char*)PR_MALLOC(PR_GetErrorTextLength());
         (void) PR_GetErrorText(error);
+#ifdef DEBUG
         fprintf(stderr, "failed to initialize shared libraries [%s]\n",
             error);
+#endif
         PR_DELETE(error);
         abort();/* XXX */
     }
 #elif defined(USE_HPSHL)
     h = NULL;
     /* don't abort with this NULL */
 #elif defined(USE_MACH_DYLD)
     h = NULL; /* XXXX  toshok */
@@ -589,20 +591,24 @@ static void* TV2FP(CFMutableDictionaryRe
                 glueData = CFDataCreateMutable(NULL, sizeof(glue));
                 if (glueData != NULL) {
                     newGlue = (uint32*) CFDataGetMutableBytePtr(glueData);
                     memcpy(newGlue, glue, sizeof(glue));
                     newGlue[0] |= ((UInt32)tvp >> 16);
                     newGlue[1] |= ((UInt32)tvp & 0xFFFF);
                     MakeDataExecutable(newGlue, sizeof(glue));
                     CFDictionaryAddValue(dict, nameRef, glueData);
+#ifdef DEBUG
                     printf("[TV2FP:  created wrapper for CFM function %s().]\n", name);
+#endif
                 }
             } else {
+#ifdef DEBUG
                 printf("[TV2FP:  found wrapper for CFM function %s().]\n", name);
+#endif
                 newGlue = (uint32*) CFDataGetMutableBytePtr(glueData);
             }
             CFRelease(nameRef);
         }
     }
     
     return newGlue;
 }
@@ -772,17 +778,19 @@ pr_LoadLibraryByPathname(const char *nam
             PR_DELETE(lm);
             goto unlock;
         }
 
         /* Resolve an alias if this was one */
         err = ResolveAliasFile(&fileSpec, true, &tempUnusedBool, &tempUnusedBool);
         if (err != noErr)
         {
+#ifdef DEBUG
             printf("[NSPR:  oops couldn't resolve an alias.]\n");
+#endif
             oserr = err;
             PR_DELETE(lm);
             goto unlock;
         }
 
         /* Finally, try to load the library */
         err = GetDiskFragment(&fileSpec, 0, kCFragGoesToEOF, fileSpec.name, 
                               kLoadCFrag, &lm->connection, &lm->main, errName);
@@ -800,17 +808,19 @@ pr_LoadLibraryByPathname(const char *nam
                 lm->main = TV2FP(lm->wrappers, "main", lm->main);
             }
         }
         
         if (err != noErr) {
 #if TARGET_CARBON
             /* If not a CFM library, perhaps it's a CFBundle. */
             lm->bundle = getLibraryBundle(&fileSpec);
+#ifdef DEBUG
             if (lm->bundle) printf("[NSPR:  bundle loaded succesfully: %s]\n", name);
+#endif
             if (lm->bundle == NULL) {
 #if defined(USE_MACH_DYLD)
                 goto next;
 #else
                 oserr = err;
                 PR_DELETE(lm);
                 goto unlock;
 #endif
@@ -821,16 +831,23 @@ pr_LoadLibraryByPathname(const char *nam
             goto unlock;
 #endif
         }
     }
     
     lm->name = strdup(libName);
     lm->next = pr_loadmap;
     pr_loadmap = lm;
+    /*
+     * we need to initalize the refCount here because the goto success skips over
+     * the code which would ordinarily set it below (below the #ifdef XP_UNIX
+     * code.) This is ugly, but there is no truly good way to deal with this
+     * without re-writing this function.
+     */
+    lm->refCount = 1;
     goto success;
     }
   next:
 #endif
 
 #ifdef XP_UNIX
 #ifdef HAVE_DLL
     {
@@ -1298,18 +1315,19 @@ pr_FindSymbolInLib(PRLibrary *lm, const 
         }
     }
 #endif
     if (lm->connection) {
         Ptr                 symAddr;
         CFragSymbolClass    symClass;
         Str255              pName;
         
+#ifdef DEBUG
         printf("[NSPR: looking up symbol:  %s]\n", name + SYM_OFFSET);
-        
+#endif        
         PStrFromCStr(name + SYM_OFFSET, pName);
         
         f = (FindSymbol(lm->connection, pName, &symAddr, &symClass) == noErr) ? symAddr : NULL;
         
 #if defined(XP_MACOSX)
         // callers expect mach-o function pointers, so must wrap tvectors with glue.
         if (f && symClass == kTVectorCFragSymbol) {
             f = TV2FP(lm->wrappers, name + SYM_OFFSET, f);