From 00424b635973703a8be19e0fb99992c934649553 Mon Sep 17 00:00:00 2001 From: Shawn Wilsher Date: Wed, 3 Mar 2010 12:55:37 -0800 Subject: [PATCH] Bug 549882 - ###!!! ASSERTION: Trying to unregister a node that wasn't registered! Also adds some assertions to make sure we do not leak the observer arrays. r=dietrich --- toolkit/components/places/src/History.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/toolkit/components/places/src/History.cpp b/toolkit/components/places/src/History.cpp index cf4854ae70af..7d6e348deda1 100644 --- a/toolkit/components/places/src/History.cpp +++ b/toolkit/components/places/src/History.cpp @@ -163,6 +163,12 @@ History::History() History::~History() { gService = NULL; +#ifdef DEBUG + if (mObservers.IsInitialized()) { + NS_ASSERTION(mObservers.Count() == 0, + "Not all Links were removed before we disappear!"); + } +#endif } void @@ -241,18 +247,24 @@ History::RegisterVisitedCallback(nsIURI* aURI, } // Obtain our array of observers for this URI. +#ifdef DEBUG + bool keyAlreadyExists = !!mObservers.GetEntry(aURI); +#endif KeyClass* key = mObservers.PutEntry(aURI); NS_ENSURE_TRUE(key, NS_ERROR_OUT_OF_MEMORY); ObserverArray& observers = key->array; if (observers.IsEmpty()) { + NS_ASSERTION(!keyAlreadyExists, + "An empty key was kept around in our hashtable!"); + // We are the first Link node to ask about this URI, or there are no pending // Links wanting to know about this URI. Therefore, we should query the // database now. nsresult rv = VisitedQuery::Start(aURI); if (NS_FAILED(rv)) { - // Curses - unregister and return failure. - (void)UnregisterVisitedCallback(aURI, aLink); + // Remove our array from the hashtable so we don't keep it around. + mObservers.RemoveEntry(aURI); return rv; } }