From fd802e3e91d3d1408de6b79564000b50776b399c Mon Sep 17 00:00:00 2001 From: "sayrer@gmail.com" Date: Wed, 23 Jan 2008 12:52:57 -0800 Subject: [PATCH] Bug 383939. All RDF datasources must implement cycle collection to avoid leaking. r/sr=bsmedberg --- content/xul/document/src/nsXULDocument.cpp | 3 +- rdf/datasource/src/nsFileSystemDataSource.cpp | 7 +- rdf/datasource/src/nsFileSystemDataSource.h | 4 +- rdf/datasource/src/nsLocalStore.cpp | 70 ++++++------------- 4 files changed, 32 insertions(+), 52 deletions(-) diff --git a/content/xul/document/src/nsXULDocument.cpp b/content/xul/document/src/nsXULDocument.cpp index 0f26898c7c78..a6366b446d76 100644 --- a/content/xul/document/src/nsXULDocument.cpp +++ b/content/xul/document/src/nsXULDocument.cpp @@ -345,8 +345,9 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsXULDocument, nsXMLDocument) for (i = 0; i < count; ++i) { cb.NoteXPCOMChild(static_cast(tmp->mPrototypes[i])); } - + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mTooltipNode) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLocalStore) if (tmp->mOverlayLoadObservers.IsInitialized()) tmp->mOverlayLoadObservers.EnumerateRead(TraverseObservers, &cb); diff --git a/rdf/datasource/src/nsFileSystemDataSource.cpp b/rdf/datasource/src/nsFileSystemDataSource.cpp index 6ade67d8fe52..cd1bf5eb8fc1 100644 --- a/rdf/datasource/src/nsFileSystemDataSource.cpp +++ b/rdf/datasource/src/nsFileSystemDataSource.cpp @@ -251,7 +251,12 @@ FileSystemDataSource::Create(nsISupports* aOuter, const nsIID& aIID, void **aRes return self->QueryInterface(aIID, aResult); } -NS_IMPL_ISUPPORTS1(FileSystemDataSource, nsIRDFDataSource) +NS_IMPL_CYCLE_COLLECTION_0(FileSystemDataSource) +NS_IMPL_CYCLE_COLLECTING_ADDREF(FileSystemDataSource) +NS_IMPL_CYCLE_COLLECTING_RELEASE(FileSystemDataSource) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FileSystemDataSource) + NS_INTERFACE_MAP_ENTRY(nsIRDFDataSource) +NS_INTERFACE_MAP_END NS_IMETHODIMP FileSystemDataSource::GetURI(char **uri) diff --git a/rdf/datasource/src/nsFileSystemDataSource.h b/rdf/datasource/src/nsFileSystemDataSource.h index 5b6125d37e4f..11d1c56b2be3 100644 --- a/rdf/datasource/src/nsFileSystemDataSource.h +++ b/rdf/datasource/src/nsFileSystemDataSource.h @@ -46,6 +46,7 @@ #include "nsISupportsArray.h" #include "nsCOMPtr.h" #include "nsString.h" +#include "nsCycleCollectionParticipant.h" #if defined(XP_UNIX) || defined(XP_OS2) || defined(XP_WIN) || defined(XP_BEOS) #define USE_NC_EXTENSION @@ -54,7 +55,8 @@ class FileSystemDataSource : public nsIRDFDataSource { public: - NS_DECL_ISUPPORTS + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_CLASS(FileSystemDataSource) NS_DECL_NSIRDFDATASOURCE static NS_METHOD Create(nsISupports* aOuter, diff --git a/rdf/datasource/src/nsLocalStore.cpp b/rdf/datasource/src/nsLocalStore.cpp index 9ff8eae5fa23..67e78717065c 100644 --- a/rdf/datasource/src/nsLocalStore.cpp +++ b/rdf/datasource/src/nsLocalStore.cpp @@ -66,6 +66,7 @@ #include "nsCRTGlue.h" #include "nsCRT.h" #include "nsEnumeratorUtils.h" +#include "nsCycleCollectionParticipant.h" //////////////////////////////////////////////////////////////////////// @@ -91,7 +92,8 @@ protected: public: // nsISupports interface - NS_DECL_ISUPPORTS + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(LocalStoreImpl, nsILocalStore) // nsILocalStore interface @@ -213,13 +215,13 @@ public: } NS_IMETHOD GetLoaded(PRBool* _result); - NS_IMETHOD Init(const char *uri); - NS_IMETHOD Flush(); - NS_IMETHOD FlushTo(const char *aURI); - NS_IMETHOD Refresh(PRBool sync); - - // nsIObserver - NS_DECL_NSIOBSERVER + NS_IMETHOD Init(const char *uri); + NS_IMETHOD Flush(); + NS_IMETHOD FlushTo(const char *aURI); + NS_IMETHOD Refresh(PRBool sync); + + // nsIObserver + NS_DECL_NSIOBSERVER }; //////////////////////////////////////////////////////////////////////// @@ -264,51 +266,21 @@ NS_NewLocalStore(nsISupports* aOuter, REFNSIID aIID, void** aResult) return rv; } +NS_IMPL_CYCLE_COLLECTION_1(LocalStoreImpl, mInner) +NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(LocalStoreImpl, nsILocalStore) +NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(LocalStoreImpl, nsILocalStore) -// nsISupports interface - -NS_IMPL_ADDREF(LocalStoreImpl) -NS_IMPL_RELEASE(LocalStoreImpl) - -NS_IMETHODIMP -LocalStoreImpl::QueryInterface(REFNSIID aIID, void** aResult) -{ -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); - - NS_PRECONDITION(aResult != nsnull, "null ptr"); - if (! aResult) - return NS_ERROR_NULL_POINTER; - - if (aIID.Equals(kISupportsIID) || - aIID.Equals(NS_GET_IID(nsILocalStore))) { - *aResult = static_cast(this); - } - else if (aIID.Equals(NS_GET_IID(nsIRDFDataSource))) { - *aResult = static_cast(this); - } - else if (aIID.Equals(NS_GET_IID(nsIRDFRemoteDataSource))) { - *aResult = static_cast(this); - } - else if (aIID.Equals(NS_GET_IID(nsIObserver))) { - *aResult = static_cast(this); - } - else if (aIID.Equals(NS_GET_IID(nsISupportsWeakReference))) { - *aResult = static_cast(this); - } - else { - *aResult = nsnull; - return NS_NOINTERFACE; - } - - NS_ADDREF(this); - return NS_OK; -} - +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(LocalStoreImpl) + NS_INTERFACE_MAP_ENTRY(nsILocalStore) + NS_INTERFACE_MAP_ENTRY(nsIRDFDataSource) + NS_INTERFACE_MAP_ENTRY(nsIRDFRemoteDataSource) + NS_INTERFACE_MAP_ENTRY(nsIObserver) + NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsILocalStore) +NS_INTERFACE_MAP_END // nsILocalStore interface - - // nsIRDFDataSource interface NS_IMETHODIMP