From 2dec45317484e91f353f6f6c5b3924fec92a13c8 Mon Sep 17 00:00:00 2001 From: "darin%netscape.com" Date: Tue, 28 Jan 2003 19:13:52 +0000 Subject: [PATCH] fixes one of the crashes reported in bug 190326 "crash in nsJARChannel.cpp when launching calendar" r=dougt sr=bzbarsky a=asa git-svn-id: svn://10.0.0.236/trunk@137035 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/modules/libjar/nsJARChannel.cpp | 40 ++++++++++++------- .../netwerk/protocol/jar/src/nsJARChannel.cpp | 40 ++++++++++++------- 2 files changed, 50 insertions(+), 30 deletions(-) diff --git a/mozilla/modules/libjar/nsJARChannel.cpp b/mozilla/modules/libjar/nsJARChannel.cpp index 4575e96e406..cf100c73c11 100644 --- a/mozilla/modules/libjar/nsJARChannel.cpp +++ b/mozilla/modules/libjar/nsJARChannel.cpp @@ -59,6 +59,7 @@ public: : mJarCache(jarCache) , mJarFile(jarFile) , mJarEntry(jarEntry) + , mContentLength(-1) { NS_ASSERTION(mJarFile, "no jar file"); } @@ -66,7 +67,12 @@ public: void GetJarReader(nsIZipReader **result) { - NS_ADDREF(*result = mJarReader); + NS_IF_ADDREF(*result = mJarReader); + } + + PRInt32 GetContentLength() + { + return mContentLength; } private: @@ -77,6 +83,7 @@ private: nsCOMPtr mJarFile; nsCOMPtr mJarStream; nsCString mJarEntry; + PRInt32 mContentLength; }; NS_IMPL_THREADSAFE_ISUPPORTS1(nsJARInputThunk, nsIInputStream) @@ -87,11 +94,22 @@ nsJARInputThunk::EnsureJarStream() if (mJarStream) return NS_OK; - nsresult rv = mJarCache->GetZip(mJarFile, getter_AddRefs(mJarReader)); + nsresult rv; + + rv = mJarCache->GetZip(mJarFile, getter_AddRefs(mJarReader)); if (NS_FAILED(rv)) return rv; - return mJarReader->GetInputStream(mJarEntry.get(), - getter_AddRefs(mJarStream)); + rv = mJarReader->GetInputStream(mJarEntry.get(), + getter_AddRefs(mJarStream)); + if (NS_FAILED(rv)) return rv; + + // ask the zip entry for the content length + nsCOMPtr entry; + mJarReader->GetEntry(mJarEntry.get(), getter_AddRefs(entry)); + if (entry) + entry->GetRealSize((PRUint32 *) &mContentLength); + + return NS_OK; } NS_IMETHODIMP @@ -510,17 +528,9 @@ nsJARChannel::SetContentCharset(const nsACString &aContentCharset) NS_IMETHODIMP nsJARChannel::GetContentLength(PRInt32 *result) { - if (mContentLength < 0 && mJarInput) { - // ask the zip entry for the content length - nsCOMPtr jarReader; - mJarInput->GetJarReader(getter_AddRefs(jarReader)); - if (jarReader) { - nsCOMPtr entry; - jarReader->GetEntry(mJarEntry.get(), getter_AddRefs(entry)); - if (entry) - entry->GetRealSize((PRUint32 *) &mContentLength); - } - } + // if content length is unknown, query mJarInput... + if (mContentLength < 0 && mJarInput) + mContentLength = mJarInput->GetContentLength(); *result = mContentLength; return NS_OK; diff --git a/mozilla/netwerk/protocol/jar/src/nsJARChannel.cpp b/mozilla/netwerk/protocol/jar/src/nsJARChannel.cpp index 4575e96e406..cf100c73c11 100644 --- a/mozilla/netwerk/protocol/jar/src/nsJARChannel.cpp +++ b/mozilla/netwerk/protocol/jar/src/nsJARChannel.cpp @@ -59,6 +59,7 @@ public: : mJarCache(jarCache) , mJarFile(jarFile) , mJarEntry(jarEntry) + , mContentLength(-1) { NS_ASSERTION(mJarFile, "no jar file"); } @@ -66,7 +67,12 @@ public: void GetJarReader(nsIZipReader **result) { - NS_ADDREF(*result = mJarReader); + NS_IF_ADDREF(*result = mJarReader); + } + + PRInt32 GetContentLength() + { + return mContentLength; } private: @@ -77,6 +83,7 @@ private: nsCOMPtr mJarFile; nsCOMPtr mJarStream; nsCString mJarEntry; + PRInt32 mContentLength; }; NS_IMPL_THREADSAFE_ISUPPORTS1(nsJARInputThunk, nsIInputStream) @@ -87,11 +94,22 @@ nsJARInputThunk::EnsureJarStream() if (mJarStream) return NS_OK; - nsresult rv = mJarCache->GetZip(mJarFile, getter_AddRefs(mJarReader)); + nsresult rv; + + rv = mJarCache->GetZip(mJarFile, getter_AddRefs(mJarReader)); if (NS_FAILED(rv)) return rv; - return mJarReader->GetInputStream(mJarEntry.get(), - getter_AddRefs(mJarStream)); + rv = mJarReader->GetInputStream(mJarEntry.get(), + getter_AddRefs(mJarStream)); + if (NS_FAILED(rv)) return rv; + + // ask the zip entry for the content length + nsCOMPtr entry; + mJarReader->GetEntry(mJarEntry.get(), getter_AddRefs(entry)); + if (entry) + entry->GetRealSize((PRUint32 *) &mContentLength); + + return NS_OK; } NS_IMETHODIMP @@ -510,17 +528,9 @@ nsJARChannel::SetContentCharset(const nsACString &aContentCharset) NS_IMETHODIMP nsJARChannel::GetContentLength(PRInt32 *result) { - if (mContentLength < 0 && mJarInput) { - // ask the zip entry for the content length - nsCOMPtr jarReader; - mJarInput->GetJarReader(getter_AddRefs(jarReader)); - if (jarReader) { - nsCOMPtr entry; - jarReader->GetEntry(mJarEntry.get(), getter_AddRefs(entry)); - if (entry) - entry->GetRealSize((PRUint32 *) &mContentLength); - } - } + // if content length is unknown, query mJarInput... + if (mContentLength < 0 && mJarInput) + mContentLength = mJarInput->GetContentLength(); *result = mContentLength; return NS_OK;