Bug 537165: Don't hold on to OS file handles in JARs r=ak

This commit is contained in:
Taras Glek 2010-01-23 11:40:21 -05:00
Родитель d4c2344fc8
Коммит bb859fc084
4 изменённых файлов: 15 добавлений и 35 удалений

Просмотреть файл

@ -170,13 +170,7 @@ nsJAR::Open(nsIFile* zipFile)
mLock = PR_NewLock();
NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
PRFileDesc *fd = OpenFile();
NS_ENSURE_TRUE(fd, NS_ERROR_FAILURE);
nsresult rv = mZip.OpenArchive(fd);
if (NS_FAILED(rv)) Close();
return rv;
return mZip.OpenArchive(zipFile);
}
NS_IMETHODIMP
@ -408,20 +402,6 @@ nsJAR::GetJarPath(nsACString& aResult)
return mZipFile->GetNativePath(aResult);
}
PRFileDesc*
nsJAR::OpenFile()
{
nsresult rv;
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(mZipFile, &rv);
if (NS_FAILED(rv)) return nsnull;
PRFileDesc* fd;
rv = localFile->OpenNSPRFileDesc(PR_RDONLY, 0000, &fd);
if (NS_FAILED(rv)) return nsnull;
return fd;
}
//----------------------------------------------
// nsJAR private implementation
//----------------------------------------------

Просмотреть файл

@ -144,9 +144,6 @@ class nsJAR : public nsIZipReader, public nsIJAR
PRInt64 mMtime;
PRInt32 mTotalItemsInManifest;
//-- Private functions
PRFileDesc* OpenFile();
nsresult ParseManifest();
void ReportError(const char* aFilename, PRInt16 errorCode);
nsresult LoadEntry(const char* aFilename, char** aBuf,

Просмотреть файл

@ -159,8 +159,7 @@ nsresult gZlibInit(z_stream *zs)
}
nsZipHandle::nsZipHandle()
: mFd(nsnull)
, mFileData(nsnull)
: mFileData(nsnull)
, mLen(0)
, mMap(nsnull)
, mRefCnt(0)
@ -195,7 +194,6 @@ nsresult nsZipHandle::Init(PRFileDesc *fd, nsZipHandle **ret)
return NS_ERROR_OUT_OF_MEMORY;
}
handle->mFd = fd;
handle->mMap = map;
handle->mLen = (PRUint32) size;
handle->mFileData = buf;
@ -212,10 +210,6 @@ nsZipHandle::~nsZipHandle()
mFileData = nsnull;
mMap = nsnull;
}
if (mFd) {
PR_Close(mFd);
mFd = nsnull;
}
MOZ_COUNT_DTOR(nsZipHandle);
}
@ -227,9 +221,18 @@ nsZipHandle::~nsZipHandle()
//---------------------------------------------
// nsZipArchive::OpenArchive
//---------------------------------------------
nsresult nsZipArchive::OpenArchive(PRFileDesc * fd)
nsresult nsZipArchive::OpenArchive(nsIFile *aZipFile)
{
nsresult rv = nsZipHandle::Init(fd, getter_AddRefs(mFd));
nsresult rv;
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(aZipFile, &rv);
if (NS_FAILED(rv)) return rv;
PRFileDesc* fd;
rv = localFile->OpenNSPRFileDesc(PR_RDONLY, 0000, &fd);
if (NS_FAILED(rv)) return rv;
rv = nsZipHandle::Init(fd, getter_AddRefs(mFd));
PR_Close(fd);
if (NS_FAILED(rv))
return rv;

Просмотреть файл

@ -52,6 +52,7 @@
#include "zlib.h"
#include "zipstruct.h"
#include "nsAutoPtr.h"
#include "nsILocalFile.h"
class nsZipFind;
@ -132,7 +133,7 @@ public:
* @param fd File descriptor of file to open
* @return status code
*/
nsresult OpenArchive(PRFileDesc* fd);
nsresult OpenArchive(nsIFile *aZipFile);
/**
* Test the integrity of items in this archive by running
@ -227,7 +228,6 @@ public:
NS_METHOD_(nsrefcnt) Release(void);
protected:
PRFileDesc * mFd; /* OS file-descriptor */
PRUint8 * mFileData; /* pointer to mmaped file */
PRUint32 mLen; /* length of file and memory mapped area */