Bug 529820 - nsCategoryCache is slightly unsafe, r=biesi
authortimeless@mozdev.org
Thu, 19 Nov 2009 07:51:00 -0800
changeset 41666 c12bfe27e805071c16dbcf95e4024ea24a363eda
parent 41665 9b18eada106ec3f91a0c7b011882d29435f96c92
child 41667 9607c536d21abdb661517d7fb97338963c68fd4a
push idunknown
push userunknown
push dateunknown
reviewersbiesi
bugs529820
milestone1.9.3a5pre
Bug 529820 - nsCategoryCache is slightly unsafe, r=biesi
xpcom/glue/nsCategoryCache.cpp
--- a/xpcom/glue/nsCategoryCache.cpp
+++ b/xpcom/glue/nsCategoryCache.cpp
@@ -60,47 +60,49 @@ nsCategoryObserver::nsCategoryObserver(c
     return;
 
   nsCOMPtr<nsISimpleEnumerator> enumerator;
   nsresult rv = catMan->EnumerateCategory(aCategory,
                                           getter_AddRefs(enumerator));
   if (NS_FAILED(rv))
     return;
 
+  nsTArray<nsCString> entries;
   nsCOMPtr<nsISupports> entry;
   while (NS_SUCCEEDED(enumerator->GetNext(getter_AddRefs(entry)))) {
     nsCOMPtr<nsISupportsCString> entryName = do_QueryInterface(entry, &rv);
 
     if (NS_SUCCEEDED(rv)) {
       nsCAutoString categoryEntry;
       rv = entryName->GetData(categoryEntry);
 
       nsCString entryValue;
       catMan->GetCategoryEntry(aCategory,
                                categoryEntry.get(),
                                getter_Copies(entryValue));
 
       if (NS_SUCCEEDED(rv)) {
         mHash.Put(categoryEntry, entryValue);
-        mListener->EntryAdded(entryValue);
+        entries.AppendElement(entryValue);
       }
     }
   }
 
   // Now, listen for changes
   nsCOMPtr<nsIObserverService> serv =
     do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
-  if (!serv)
-    return;
+  if (serv) {
+    serv->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE);
+    serv->AddObserver(this, NS_XPCOM_CATEGORY_ENTRY_ADDED_OBSERVER_ID, PR_FALSE);
+    serv->AddObserver(this, NS_XPCOM_CATEGORY_ENTRY_REMOVED_OBSERVER_ID, PR_FALSE);
+    serv->AddObserver(this, NS_XPCOM_CATEGORY_CLEARED_OBSERVER_ID, PR_FALSE);
+  }
 
-  serv->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE);
-
-  serv->AddObserver(this, NS_XPCOM_CATEGORY_ENTRY_ADDED_OBSERVER_ID, PR_FALSE);
-  serv->AddObserver(this, NS_XPCOM_CATEGORY_ENTRY_REMOVED_OBSERVER_ID, PR_FALSE);
-  serv->AddObserver(this, NS_XPCOM_CATEGORY_CLEARED_OBSERVER_ID, PR_FALSE);
+  for (PRInt32 i = entries.Length() - 1; i >= 0; --i)
+    mListener->EntryAdded(entries[i]);
 }
 
 nsCategoryObserver::~nsCategoryObserver() {
 }
 
 NS_IMPL_ISUPPORTS1(nsCategoryObserver, nsIObserver)
 
 void