From 2bf095e76fcd6ef6ea65a46ca0a1915a4666f255 Mon Sep 17 00:00:00 2001 From: "brendan%mozilla.org" Date: Mon, 26 Nov 2001 01:20:31 +0000 Subject: [PATCH] Break self-cycle to fix leak (106860, r=dbaron, sr=bienvenu). git-svn-id: svn://10.0.0.236/trunk@108886 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/io/nsFastLoadFile.cpp | 24 +++++++++++++++--------- mozilla/xpcom/io/nsFastLoadFile.h | 5 +++-- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/mozilla/xpcom/io/nsFastLoadFile.cpp b/mozilla/xpcom/io/nsFastLoadFile.cpp index b51d5036ca8..705329aba72 100644 --- a/mozilla/xpcom/io/nsFastLoadFile.cpp +++ b/mozilla/xpcom/io/nsFastLoadFile.cpp @@ -2260,11 +2260,6 @@ nsFastLoadFileUpdater::Open(nsFastLoadFileReader* aReader) // Map from reader dense, zero-based MFL_OID_TO_SHARP_INDEX(oid) to sharp // object offset and refcnt information in updater. - PRUint32 saveReadOffset; - rv = aReader->Tell(&saveReadOffset); - if (NS_FAILED(rv)) - return rv; - nsFastLoadFileReader::nsObjectMapEntry* readObjectMap = aReader->mFooter.mObjectMap; for (i = 0, n = aReader->mFooter.mNumSharpObjects; i < n; i++) { @@ -2292,10 +2287,6 @@ nsFastLoadFileUpdater::Open(nsFastLoadFileReader* aReader) readEntry); } - rv = aReader->Seek(nsISeekableStream::NS_SEEK_SET, saveReadOffset); - if (NS_FAILED(rv)) - return rv; - // Copy URI spec string and initial segment offset in FastLoad file from // nsDocumentMapReadEntry in reader to mDocumentMapWriteEntry in updater. // If we didn't enumerate all entries, we ran out of memory. @@ -2340,11 +2331,26 @@ nsFastLoadFileUpdater::Open(nsFastLoadFileReader* aReader) if (NS_FAILED(rv)) return rv; + // Avoid creating yet another object by implementing nsIFastLoadFileIO on + // this updater, and save aReader's input stream so it can be returned by + // GetInputStream called from nsFastLoadFileWriter::Close. This requires + // that we override Close to break the resulting zero-length cycle. mFileIO = this; mInputStream = aReader->mInputStream; return NS_OK; } +NS_IMETHODIMP +nsFastLoadFileUpdater::Close() +{ + // Call base-class Close implementation, which uses mFileIO. + nsresult rv = nsFastLoadFileWriter::Close(); + + // Break degenerate cycle from this->mFileIO to this. + mFileIO = nsnull; + return rv; +} + NS_COM nsresult NS_NewFastLoadFileUpdater(nsIObjectOutputStream* *aResult, nsIOutputStream* aOutputStream, diff --git a/mozilla/xpcom/io/nsFastLoadFile.h b/mozilla/xpcom/io/nsFastLoadFile.h index cf84b8cd181..fe8d60b220c 100644 --- a/mozilla/xpcom/io/nsFastLoadFile.h +++ b/mozilla/xpcom/io/nsFastLoadFile.h @@ -445,7 +445,7 @@ class NS_COM nsFastLoadFileWriter nsresult Init(); nsresult Open(); - NS_IMETHOD Close(void); + NS_IMETHOD Close(); nsresult WriteObjectCommon(nsISupports* aObject, PRBool aIsStrongRef, @@ -521,7 +521,8 @@ class NS_COM nsFastLoadFileUpdater // nsIFastLoadFileIO methods NS_DECL_NSIFASTLOADFILEIO - nsresult Open(nsFastLoadFileReader* aReader); + nsresult Open(nsFastLoadFileReader* aReader); + NS_IMETHOD Close(); static PLDHashOperator PR_CALLBACK CopyReadDocumentMapEntryToUpdater(PLDHashTable *aTable,