Bug 392526. Some callers of nsID::ToString use a mismatched allocator to free the string. r=bsmedberg
authorDavid Zbarsky <dzbarsky@gmail.com>
Wed, 29 Jul 2009 13:54:44 -0400
changeset 30833 44fab2f1ab6464c31f431e17e2b524d7767f2f72
parent 30832 82f131218d0941ab055652f4fe0636326df47dbb
child 30834 cae7b01ca38f9f79b45b7836232cb8c432fd4269
push id8271
push userbzbarsky@mozilla.com
push dateWed, 29 Jul 2009 17:56:09 +0000
treeherdermozilla-central@44fab2f1ab64 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs392526
milestone1.9.2a1pre
Bug 392526. Some callers of nsID::ToString use a mismatched allocator to free the string. r=bsmedberg
caps/src/nsScriptSecurityManager.cpp
extensions/java/xpcom/src/nsJavaWrapper.cpp
extensions/java/xpcom/src/nsJavaXPCOMBindingUtils.cpp
extensions/java/xpcom/src/nsJavaXPTCStub.cpp
intl/uconv/public/nsEncoderDecoderUtils.h
js/src/xpconnect/src/xpcwrappedjs.cpp
js/src/xpconnect/src/xpcwrappedjsclass.cpp
--- a/caps/src/nsScriptSecurityManager.cpp
+++ b/caps/src/nsScriptSecurityManager.cpp
@@ -2858,17 +2858,17 @@ nsScriptSecurityManager::CanCreateWrappe
                                           const nsIID &aIID,
                                           nsISupports *aObj,
                                           nsIClassInfo *aClassInfo,
                                           void **aPolicy)
 {
 #ifdef DEBUG_CAPS_CanCreateWrapper
     char* iidStr = aIID.ToString();
     printf("### CanCreateWrapper(%s) ", iidStr);
-    nsCRT::free(iidStr);
+    NS_Free(iidStr);
 #endif
 // XXX Special case for nsIXPCException ?
     ClassInfoData objClassInfo = ClassInfoData(aClassInfo, nsnull);
     if (objClassInfo.IsDOMClass())
     {
 #ifdef DEBUG_CAPS_CanCreateWrapper
         printf("DOM class - GRANTED.\n");
 #endif
@@ -2987,17 +2987,17 @@ nsScriptSecurityManager::CheckComponentP
 
 NS_IMETHODIMP
 nsScriptSecurityManager::CanCreateInstance(JSContext *cx,
                                            const nsCID &aCID)
 {
 #ifdef DEBUG_CAPS_CanCreateInstance
     char* cidStr = aCID.ToString();
     printf("### CanCreateInstance(%s) ", cidStr);
-    nsCRT::free(cidStr);
+    NS_Free(cidStr);
 #endif
 
     nsresult rv = CheckXPCPermissions(nsnull, nsnull, nsnull, nsnull);
     if (NS_FAILED(rv))
 #ifdef XPC_IDISPATCH_SUPPORT
     {
         rv = CheckComponentPermissions(cx, aCID);
     }
@@ -3024,17 +3024,17 @@ nsScriptSecurityManager::CanCreateInstan
 
 NS_IMETHODIMP
 nsScriptSecurityManager::CanGetService(JSContext *cx,
                                        const nsCID &aCID)
 {
 #ifdef DEBUG_CAPS_CanGetService
     char* cidStr = aCID.ToString();
     printf("### CanGetService(%s) ", cidStr);
-    nsCRT::free(cidStr);
+    NS_Free(cidStr);
 #endif
 
     nsresult rv = CheckXPCPermissions(nsnull, nsnull, nsnull, nsnull);
     if (NS_FAILED(rv))
     {
         //-- Access denied, report an error
         nsCAutoString errorMsg("Permission denied to get service. CID=");
         char cidStr[NSID_LENGTH];
--- a/extensions/java/xpcom/src/nsJavaWrapper.cpp
+++ b/extensions/java/xpcom/src/nsJavaWrapper.cpp
@@ -1796,17 +1796,17 @@ GetNewOrUsedJavaWrapper(JNIEnv* env, nsI
 
     if (java_obj) {
 #ifdef DEBUG_JAVAXPCOM
       char* iid_str = aIID.ToString();
       LOG(("+ CreateJavaProxy (Java=%08x | XPCOM=%08x | IID=%s)\n",
            (PRUint32) env->CallStaticIntMethod(systemClass, hashCodeMID,
                                                java_obj),
            (PRUint32) rootObject, iid_str));
-      PR_Free(iid_str);
+      NS_Free(iid_str);
 #endif
 
       // Associate XPCOM object with Java proxy
       rv = gNativeToJavaProxyMap->Add(env, rootObject, aIID, java_obj);
       if (NS_SUCCEEDED(rv)) {
         *aResult = java_obj;
         return NS_OK;
       }
@@ -1839,17 +1839,17 @@ GetXPCOMInstFromProxy(JNIEnv* env, jobje
   JavaXPCOMInstance* inst = static_cast<JavaXPCOMInstance*>(*aResult);
   nsIID* iid;
   inst->InterfaceInfo()->GetInterfaceIID(&iid);
   char* iid_str = iid->ToString();
   LOG(("< GetXPCOMInstFromProxy (Java=%08x | XPCOM=%08x | IID=%s)\n",
        (PRUint32) env->CallStaticIntMethod(systemClass, hashCodeMID,
                                            aJavaObject),
        (PRUint32) inst->GetInstance(), iid_str));
-  PR_Free(iid_str);
+  NS_Free(iid_str);
   nsMemory::Free(iid);
 #endif
   return NS_OK;
 }
 
 /**
  *  org.mozilla.xpcom.internal.XPCOMJavaProxy.finalizeProxy
  */
--- a/extensions/java/xpcom/src/nsJavaXPCOMBindingUtils.cpp
+++ b/extensions/java/xpcom/src/nsJavaXPCOMBindingUtils.cpp
@@ -485,17 +485,17 @@ DestroyJavaProxyMappingEnum(PLDHashTable
     if (NS_SUCCEEDED(rv)) {
       JavaXPCOMInstance* inst = static_cast<JavaXPCOMInstance*>(xpcom_obj);
 #ifdef DEBUG_JAVAXPCOM
       char* iid_str = item->iid.ToString();
       LOG(("- NativeToJavaProxyMap (Java=%08x | XPCOM=%08x | IID=%s)\n",
            (PRUint32) env->CallStaticIntMethod(systemClass, hashCodeMID,
                                                javaObject),
            (PRUint32) entry, iid_str));
-      PR_Free(iid_str);
+      NS_Free(iid_str);
 #endif
       delete inst;  // releases native XPCOM object
     }
 
     NativeToJavaProxyMap::ProxyList* next = item->next;
     env->CallVoidMethod(item->javaObject, clearReferentMID);
     env->DeleteGlobalRef(item->javaObject);
     delete item;
@@ -543,17 +543,17 @@ NativeToJavaProxyMap::Add(JNIEnv* env, n
   e->key = aXPCOMObject;
   e->list = item;
 
 #ifdef DEBUG_JAVAXPCOM
   char* iid_str = aIID.ToString();
   LOG(("+ NativeToJavaProxyMap (Java=%08x | XPCOM=%08x | IID=%s)\n",
        (PRUint32) env->CallStaticIntMethod(systemClass, hashCodeMID, aProxy),
        (PRUint32) aXPCOMObject, iid_str));
-  PR_Free(iid_str);
+  NS_Free(iid_str);
 #endif
   return NS_OK;
 }
 
 nsresult
 NativeToJavaProxyMap::Find(JNIEnv* env, nsISupports* aNativeObject,
                            const nsIID& aIID, jobject* aResult)
 {
@@ -579,17 +579,17 @@ NativeToJavaProxyMap::Find(JNIEnv* env, 
       if (!env->IsSameObject(referentObj, NULL)) {
         *aResult = referentObj;
 #ifdef DEBUG_JAVAXPCOM
         char* iid_str = aIID.ToString();
         LOG(("< NativeToJavaProxyMap (Java=%08x | XPCOM=%08x | IID=%s)\n",
              (PRUint32) env->CallStaticIntMethod(systemClass, hashCodeMID,
                                                  *aResult),
              (PRUint32) aNativeObject, iid_str));
-        PR_Free(iid_str);
+        NS_Free(iid_str);
 #endif
       }
     }
     item = item->next;
   }
 
   return NS_OK;
 }
@@ -615,17 +615,17 @@ NativeToJavaProxyMap::Remove(JNIEnv* env
   while (item != nsnull) {
     if (item->iid.Equals(aIID)) {
 #ifdef DEBUG_JAVAXPCOM
       char* iid_str = aIID.ToString();
       LOG(("- NativeToJavaProxyMap (Java=%08x | XPCOM=%08x | IID=%s)\n",
            (PRUint32) env->CallStaticIntMethod(systemClass, hashCodeMID,
                                                item->javaObject),
            (PRUint32) aNativeObject, iid_str));
-      PR_Free(iid_str);
+      NS_Free(iid_str);
 #endif
 
       env->CallVoidMethod(item->javaObject, clearReferentMID);
       env->DeleteGlobalRef(item->javaObject);
       if (item == e->list) {
         e->list = item->next;
         if (e->list == nsnull)
           PL_DHashTableOperate(mHashTable, aNativeObject, PL_DHASH_REMOVE);
@@ -704,17 +704,17 @@ JavaToXPTCStubMap::Add(jint aJavaObjectH
 #ifdef DEBUG_JAVAXPCOM
   nsIInterfaceInfo* iface_info;
   aProxy->GetInterfaceInfo(&iface_info);
   nsIID* iid;
   iface_info->GetInterfaceIID(&iid);
   char* iid_str = iid->ToString();
   LOG(("+ JavaToXPTCStubMap (Java=%08x | XPCOM=%08x | IID=%s)\n",
        (PRUint32) aJavaObjectHashCode, (PRUint32) aProxy, iid_str));
-  PR_Free(iid_str);
+  NS_Free(iid_str);
   nsMemory::Free(iid);
   NS_RELEASE(iface_info);
 #endif
   return NS_OK;
 }
 
 nsresult
 JavaToXPTCStubMap::Find(jint aJavaObjectHashCode, const nsIID& aIID,
--- a/extensions/java/xpcom/src/nsJavaXPTCStub.cpp
+++ b/extensions/java/xpcom/src/nsJavaXPTCStub.cpp
@@ -67,17 +67,17 @@ nsJavaXPTCStub::nsJavaXPTCStub(jobject a
   mJavaWeakRef = env->NewGlobalRef(weakref);
   mJavaRefHashCode = env->CallStaticIntMethod(systemClass, hashCodeMID,
                                               aJavaObject);
 
 #ifdef DEBUG_JAVAXPCOM
   char* iid_str = iid->ToString();
   LOG(("+ nsJavaXPTCStub (Java=%08x | XPCOM=%08x | IID=%s)\n",
       (PRUint32) mJavaRefHashCode, (PRUint32) this, iid_str));
-  PR_Free(iid_str);
+  NS_Free(iid_str);
 #endif
 }
 
 nsJavaXPTCStub::~nsJavaXPTCStub()
 {
 }
 
 NS_IMETHODIMP_(nsrefcnt)
@@ -107,17 +107,17 @@ nsJavaXPTCStub::AddRef()
 {
 #ifdef DEBUG_JAVAXPCOM_REFCNT
   nsIID* iid;
   mIInfo->GetInterfaceIID(&iid);
   char* iid_str = iid->ToString();
   int refcnt = PRInt32(mMaster ? mMaster->mRefCnt : mRefCnt) + 1;
   LOG(("= nsJavaXPTCStub::AddRef (XPCOM=%08x | refcnt = %d | IID=%s)\n",
        (int) this, refcnt, iid_str));
-  PR_Free(iid_str);
+  NS_Free(iid_str);
   nsMemory::Free(iid);
 #endif
 
   nsJavaXPTCStub* master = mMaster ? mMaster : this;
   return master->AddRefInternal();
 }
 
 NS_IMETHODIMP_(nsrefcnt)
@@ -147,17 +147,17 @@ nsJavaXPTCStub::Release()
 {
 #ifdef DEBUG_JAVAXPCOM_REFCNT
   nsIID* iid;
   mIInfo->GetInterfaceIID(&iid);
   char* iid_str = iid->ToString();
   int refcnt = PRInt32(mMaster ? mMaster->mRefCnt : mRefCnt) - 1;
   LOG(("= nsJavaXPTCStub::Release (XPCOM=%08x | refcnt = %d | IID=%s)\n",
        (int) this, refcnt, iid_str));
-  PR_Free(iid_str);
+  NS_Free(iid_str);
   nsMemory::Free(iid);
 #endif
 
   nsJavaXPTCStub* master = mMaster ? mMaster : this;
   return master->ReleaseInternal();
 }
 
 void
@@ -166,17 +166,17 @@ nsJavaXPTCStub::Destroy()
   JNIEnv* env = GetJNIEnv();
 
 #ifdef DEBUG_JAVAXPCOM
   nsIID* iid;
   mIInfo->GetInterfaceIID(&iid);
   char* iid_str = iid->ToString();
   LOG(("- nsJavaXPTCStub (Java=%08x | XPCOM=%08x | IID=%s)\n",
       (PRUint32) mJavaRefHashCode, (PRUint32) this, iid_str));
-  PR_Free(iid_str);
+  NS_Free(iid_str);
   nsMemory::Free(iid);
 #endif
 
   if (!mMaster) {
     // delete each child stub
     for (PRInt32 i = 0; i < mChildren.Count(); i++) {
       delete (nsJavaXPTCStub*) mChildren[i];
     }
@@ -288,17 +288,17 @@ nsJavaXPTCStub::QueryInterface(const nsI
   char* iid_str = aIID.ToString();
   if (iid_str) {
     iid_jstr = env->NewStringUTF(iid_str);
   }
   if (!iid_str || !iid_jstr) {
     env->ExceptionClear();
     return NS_ERROR_OUT_OF_MEMORY;
   }
-  PR_Free(iid_str);
+  NS_Free(iid_str);
 
   // call queryInterface method
   jobject obj = env->CallObjectMethod(javaObject, qiMID, iid_jstr);
   if (env->ExceptionCheck()) {
     env->ExceptionClear();
     return NS_ERROR_FAILURE;
   }
   if (!obj)
@@ -1648,17 +1648,17 @@ nsJavaXPTCStub::GetJavaObject()
   jobject javaObject = env->CallObjectMethod(mJavaWeakRef, getReferentMID);
 
 #ifdef DEBUG_JAVAXPCOM
   nsIID* iid;
   mIInfo->GetInterfaceIID(&iid);
   char* iid_str = iid->ToString();
   LOG(("< nsJavaXPTCStub (Java=%08x | XPCOM=%08x | IID=%s)\n",
        (PRUint32) mJavaRefHashCode, (PRUint32) this, iid_str));
-  PR_Free(iid_str);
+  NS_Free(iid_str);
   nsMemory::Free(iid);
 #endif
 
   return javaObject;
 }
 
 
 /*static*/ nsresult
--- a/intl/uconv/public/nsEncoderDecoderUtils.h
+++ b/intl/uconv/public/nsEncoderDecoderUtils.h
@@ -118,20 +118,17 @@ nsUConverterUnregSelf(nsIComponentManage
                                                                         \
     if (entry->isEncoder) {                                             \
       category = NS_UNICODEDECODER_NAME;                                \
     } else {                                                            \
       category = NS_UNICODEENCODER_NAME;                                \
     }                                                                   \
     key = entry->charset;                                               \
                                                                         \
-    char * value = entry->cid.ToString();                               \
-                                                                        \
     rv = catman->DeleteCategoryEntry(category, key, PR_TRUE);           \
-    CRTFREEIF(value);                                                   \
   }                                                                     \
   return rv;                                                            \
 }
 
 
 #define NS_UCONV_REG_UNREG_DECODER(_Charset, _CID)          \
   {                                                         \
     PR_FALSE,                                                \
--- a/js/src/xpconnect/src/xpcwrappedjs.cpp
+++ b/js/src/xpconnect/src/xpcwrappedjs.cpp
@@ -643,17 +643,17 @@ nsXPCWrappedJS::DebugDump(PRInt16 depth)
         char* name;
         GetClass()->GetInterfaceInfo()->GetName(&name);
         XPC_LOG_ALWAYS(("interface name is %s", name));
         if(name)
             nsMemory::Free(name);
         char * iid = GetClass()->GetIID().ToString();
         XPC_LOG_ALWAYS(("IID number is %s", iid ? iid : "invalid"));
         if(iid)
-            PR_Free(iid);
+            NS_Free(iid);
         XPC_LOG_ALWAYS(("nsXPCWrappedJSClass @ %x", mClass));
 
         if(!isRoot)
             XPC_LOG_OUTDENT();
         if(mNext)
         {
             if(isRoot)
             {
--- a/js/src/xpconnect/src/xpcwrappedjsclass.cpp
+++ b/js/src/xpconnect/src/xpcwrappedjsclass.cpp
@@ -1942,17 +1942,17 @@ nsXPCWrappedJSClass::DebugDump(PRInt16 d
         char* name;
         mInfo->GetName(&name);
         XPC_LOG_ALWAYS(("interface name is %s", name));
         if(name)
             nsMemory::Free(name);
         char * iid = mIID.ToString();
         XPC_LOG_ALWAYS(("IID number is %s", iid ? iid : "invalid"));
         if(iid)
-            PR_Free(iid);
+            NS_Free(iid);
         XPC_LOG_ALWAYS(("InterfaceInfo @ %x", mInfo));
         uint16 methodCount = 0;
         if(depth)
         {
             uint16 i;
             nsCOMPtr<nsIInterfaceInfo> parent;
             XPC_LOG_INDENT();
             mInfo->GetParent(getter_AddRefs(parent));