diff --git a/modules/libjar/nsJARInputStream.cpp b/modules/libjar/nsJARInputStream.cpp index 6e88853b0263..b86e45ebf9d6 100644 --- a/modules/libjar/nsJARInputStream.cpp +++ b/modules/libjar/nsJARInputStream.cpp @@ -40,7 +40,7 @@ nsJARInputStream::Available(PRUint32 *_retval) if (Zip() == nsnull) *_retval = 0; else - *_retval = Zip()->Available(mReadInfo); + *_retval = Zip()->Available(&mReadInfo); return NS_OK; } @@ -54,7 +54,7 @@ nsJARInputStream::Read(char* buf, PRUint32 count, PRUint32 *bytesRead) return NS_OK; } - PRInt32 err = Zip()->Read(mReadInfo, buf, count, bytesRead); + PRInt32 err = Zip()->Read(&mReadInfo, buf, count, bytesRead); return err == ZIP_OK ? NS_OK : NS_ERROR_FAILURE; } @@ -103,8 +103,6 @@ NS_IMETHODIMP nsJARInputStream::Close() { NS_IF_RELEASE(mJAR); - if (mReadInfo) - delete mReadInfo; return NS_OK; } @@ -140,7 +138,7 @@ nsJARInputStream::Create(nsISupports* ignored, const nsIID& aIID, void* *aResult //---------------------------------------------- nsJARInputStream::nsJARInputStream() - : mJAR(nsnull), mReadInfo(nsnull) + : mJAR(nsnull) { NS_INIT_REFCNT(); } diff --git a/modules/libjar/nsJARInputStream.h b/modules/libjar/nsJARInputStream.h index d5be1ee08684..fd4cd9794a4f 100644 --- a/modules/libjar/nsJARInputStream.h +++ b/modules/libjar/nsJARInputStream.h @@ -60,7 +60,7 @@ class nsJARInputStream : public nsIInputStream protected: nsJAR* mJAR; - nsZipRead* mReadInfo; + nsZipRead mReadInfo; }; #endif /* nsJAR_h__ */ diff --git a/modules/libjar/nsZipArchive.cpp b/modules/libjar/nsZipArchive.cpp index 58b914c44a70..53f1f49f1be8 100644 --- a/modules/libjar/nsZipArchive.cpp +++ b/modules/libjar/nsZipArchive.cpp @@ -667,7 +667,7 @@ PRInt32 nsZipArchive::GetItem( const char * aFilename, nsZipItem **result) //--------------------------------------------- // nsZipArchive::ReadInit //--------------------------------------------- -PRInt32 nsZipArchive::ReadInit(const char* zipEntry, nsZipRead** aRead) +PRInt32 nsZipArchive::ReadInit(const char* zipEntry, nsZipRead* aRead) { //-- Parameter validity check if (zipEntry == 0 || aRead == 0) @@ -680,10 +680,8 @@ PRInt32 nsZipArchive::ReadInit(const char* zipEntry, nsZipRead** aRead) if (!item) return ZIP_ERR_FNF; - //-- Create nsZipRead object - *aRead = new nsZipRead(this, item); - if (aRead == 0) - return ZIP_ERR_MEMORY; + //-- Initialize nsZipRead object + aRead->Init(this, item); //-- Read the item into memory // Inflate if necessary and save in mInflatedFileBuffer @@ -704,7 +702,7 @@ PRInt32 nsZipArchive::ReadInit(const char* zipEntry, nsZipRead** aRead) } if (result == ZIP_OK) - (*aRead)->mFileBuffer = buf; + aRead->mFileBuffer = buf; return result; } @@ -1735,27 +1733,11 @@ nsZipItem::~nsZipItem() } //------------------------------------------ -// nsZipRead constructor and destructor +// nsZipRead //------------------------------------------ MOZ_DECL_CTOR_COUNTER(nsZipRead) -nsZipRead::nsZipRead( nsZipArchive* aZipArchive, nsZipItem* aZipItem ) -: mArchive(aZipArchive), - mItem(aZipItem), - mCurPos(0), - mFileBuffer(0) -{ - MOZ_COUNT_CTOR(nsZipRead); -} - -nsZipRead::~nsZipRead() -{ - PR_FREEIF(mFileBuffer); - - MOZ_COUNT_DTOR(nsZipRead); -} - //------------------------------------------ // nsZipFind constructor and destructor //------------------------------------------ diff --git a/modules/libjar/nsZipArchive.h b/modules/libjar/nsZipArchive.h index 764c1b5a7311..bdacc869a367 100644 --- a/modules/libjar/nsZipArchive.h +++ b/modules/libjar/nsZipArchive.h @@ -163,10 +163,10 @@ public: * before any calls to Read or Available * * @param zipEntry name of item in file - * @param (out) a structure used by Read and Available + * @param aRead is filled with appropriate values * @return status code */ - PRInt32 ReadInit(const char* zipEntry, nsZipRead** aRead); + PRInt32 ReadInit(const char* zipEntry, nsZipRead* aRead); /** * Read @@ -269,8 +269,20 @@ class nsZipRead { public: - nsZipRead( nsZipArchive* aZip, nsZipItem* item ); - ~nsZipRead(); + nsZipRead() { MOZ_COUNT_CTOR(nsZipRead); } + ~nsZipRead() + { + PR_FREEIF(mFileBuffer); + MOZ_COUNT_DTOR(nsZipRead); + } + + void Init( nsZipArchive* aZip, nsZipItem* aZipItem ) + { + mArchive = aZip; + mItem = aZipItem; + mCurPos = 0; + mFileBuffer = NULL; + } nsZipArchive* mArchive; nsZipItem* mItem;