Don't close the same file descriptors twice. b=367817 r+sr=darin

This commit is contained in:
dbaron%dbaron.org 2007-01-25 23:05:22 +00:00
parent 18678c0da7
commit 34b9845adc
3 changed files with 14 additions and 6 deletions

View File

@ -326,7 +326,6 @@ nsJAR::GetInputStreamWithSpec(const nsACString& aJarDirSpec,
NS_ENSURE_ARG_POINTER(result);
// Watch out for the jar:foo.zip!/ (aDir is empty) top-level special case!
PRFileDesc *fd = nsnull;
nsZipItem *item = nsnull;
if (*aEntryName) {
// First check if item exists in jar
@ -343,12 +342,19 @@ nsJAR::GetInputStreamWithSpec(const nsACString& aJarDirSpec,
rv = jis->InitDirectory(&mZip, aJarDirSpec, aEntryName);
} else {
// Open jarfile, to get its own filedescriptor for the stream
// XXX The file may have been overwritten, so |item| might not be
// valid. We really want to work from inode rather than file name.
PRFileDesc *fd = nsnull;
fd = OpenFile();
rv = fd ? jis->InitFile(&mZip, item, fd) : NS_ERROR_FAILURE;
if (fd) {
rv = jis->InitFile(&mZip, item, fd);
// |jis| now owns |fd|
} else {
rv = NS_ERROR_FAILURE;
}
}
if (NS_FAILED(rv)) {
NS_RELEASE(*result);
if (fd) PR_Close(fd);
}
return rv;
}

View File

@ -61,6 +61,9 @@ nsJARInputStream::InitFile(nsZipArchive* aZip, nsZipItem *item, PRFileDesc *fd)
{
nsresult rv;
// Keep the file handle, even on failure
mFd = fd;
NS_ENSURE_ARG_POINTER(aZip);
NS_ENSURE_ARG_POINTER(item);
NS_ENSURE_ARG_POINTER(fd);
@ -68,9 +71,6 @@ nsJARInputStream::InitFile(nsZipArchive* aZip, nsZipItem *item, PRFileDesc *fd)
// Mark it as closed, in case something fails in initialisation
mClosed = PR_TRUE;
// Keep the file handle
mFd = fd;
// Keep the important bits of nsZipItem only
mInSize = item->size;

View File

@ -60,7 +60,9 @@ class nsJARInputStream : public nsIInputStream
NS_DECL_ISUPPORTS
NS_DECL_NSIINPUTSTREAM
// takes ownership of |fd|, even on failure
nsresult InitFile(nsZipArchive* aZip, nsZipItem *item, PRFileDesc *fd);
nsresult InitDirectory(nsZipArchive* aZip,
const nsACString& aJarDirSpec,
const char* aDir);