diff --git a/toolkit/components/places/src/nsNavHistory.cpp b/toolkit/components/places/src/nsNavHistory.cpp index 3a644c95da3..4ca5d36c6f5 100644 --- a/toolkit/components/places/src/nsNavHistory.cpp +++ b/toolkit/components/places/src/nsNavHistory.cpp @@ -322,6 +322,10 @@ nsNavHistory::Init() NS_ENSURE_TRUE(mRecentBookmark.Init(128), NS_ERROR_OUT_OF_MEMORY); NS_ENSURE_TRUE(mRecentRedirects.Init(128), NS_ERROR_OUT_OF_MEMORY); + rv = CreateLookupIndexes(); + if (NS_FAILED(rv)) + return rv; + // The AddObserver calls must be the last lines in this function, because // this function may fail, and thus, this object would be not completely // initialized), but the observerservice would still keep a reference to us @@ -351,7 +355,10 @@ nsNavHistory::Init() } } - return CreateLookupIndexes(); + // Don't add code that can fail here! Do it up above, before we add our + // observers. + + return NS_OK; } @@ -3789,3 +3796,22 @@ nsresult BindStatementURI(mozIStorageStatement* statement, PRInt32 index, NS_ENSURE_SUCCESS(rv, rv); return NS_OK; } + +NS_METHOD +nsNavHistory::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) +{ + NS_ENSURE_NO_AGGREGATION(aOuter); + + if (gHistoryService) + return gHistoryService->QueryInterface(aIID, aResult); + + nsRefPtr serv(new nsNavHistory()); + if (!serv) + return NS_ERROR_OUT_OF_MEMORY; + + nsresult rv = serv->Init(); + if (NS_FAILED(rv)) + return rv; + + return serv->QueryInterface(aIID, aResult); +}