win: Fix leaking of fd when reading file in asar
This commit is contained in:
parent
9b1fa04988
commit
9e90ea8734
2 changed files with 10 additions and 11 deletions
|
@ -115,6 +115,14 @@ bool FillFileInfoWithNode(Archive::FileInfo* info,
|
||||||
Archive::Archive(const base::FilePath& path)
|
Archive::Archive(const base::FilePath& path)
|
||||||
: path_(path),
|
: path_(path),
|
||||||
file_(path_, base::File::FLAG_OPEN | base::File::FLAG_READ),
|
file_(path_, base::File::FLAG_OPEN | base::File::FLAG_READ),
|
||||||
|
#if defined(OS_WIN)
|
||||||
|
fd_(_open_osfhandle(
|
||||||
|
reinterpret_cast<intptr_t>(file_.GetPlatformFile()), 0)),
|
||||||
|
#elif defined(OS_POSIX)
|
||||||
|
fd_(file_.GetPlatformFile()),
|
||||||
|
#else
|
||||||
|
fd_(-1),
|
||||||
|
#endif
|
||||||
header_size_(0) {
|
header_size_(0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,17 +279,7 @@ bool Archive::CopyFileOut(const base::FilePath& path, base::FilePath* out) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int Archive::GetFD() const {
|
int Archive::GetFD() const {
|
||||||
if (!file_.IsValid())
|
return fd_;
|
||||||
return -1;
|
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
|
||||||
return
|
|
||||||
_open_osfhandle(reinterpret_cast<intptr_t>(file_.GetPlatformFile()), 0);
|
|
||||||
#elif defined(OS_POSIX)
|
|
||||||
return file_.GetPlatformFile();
|
|
||||||
#else
|
|
||||||
return -1;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace asar
|
} // namespace asar
|
||||||
|
|
|
@ -69,6 +69,7 @@ class Archive {
|
||||||
private:
|
private:
|
||||||
base::FilePath path_;
|
base::FilePath path_;
|
||||||
base::File file_;
|
base::File file_;
|
||||||
|
int fd_;
|
||||||
uint32 header_size_;
|
uint32 header_size_;
|
||||||
scoped_ptr<base::DictionaryValue> header_;
|
scoped_ptr<base::DictionaryValue> header_;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue