Merge pull request #2886 from atom/fix-asar-leak
win: Fix leaking of fd when reading file in asar
This commit is contained in:
commit
5d26bc08ee
4 changed files with 14 additions and 21 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_;
|
||||||
|
|
||||||
|
|
|
@ -294,16 +294,6 @@ describe 'browser-window module', ->
|
||||||
w.show()
|
w.show()
|
||||||
w.minimize()
|
w.minimize()
|
||||||
|
|
||||||
describe 'will-navigate event', ->
|
|
||||||
@timeout 10000
|
|
||||||
it 'emits when user starts a navigation', (done) ->
|
|
||||||
url = "file://#{fixtures}/pages/will-navigate.html"
|
|
||||||
w.webContents.on 'will-navigate', (event, u) ->
|
|
||||||
event.preventDefault()
|
|
||||||
assert.equal u, url
|
|
||||||
done()
|
|
||||||
w.loadUrl url
|
|
||||||
|
|
||||||
xdescribe 'beginFrameSubscription method', ->
|
xdescribe 'beginFrameSubscription method', ->
|
||||||
it 'subscribes frame updates', (done) ->
|
it 'subscribes frame updates', (done) ->
|
||||||
w.loadUrl "file://#{fixtures}/api/blank.html"
|
w.loadUrl "file://#{fixtures}/api/blank.html"
|
||||||
|
|
|
@ -8,6 +8,10 @@ describe 'asar package', ->
|
||||||
|
|
||||||
describe 'node api', ->
|
describe 'node api', ->
|
||||||
describe 'fs.readFileSync', ->
|
describe 'fs.readFileSync', ->
|
||||||
|
it 'does not leak fd', ->
|
||||||
|
for i in [1..10000]
|
||||||
|
fs.readFileSync(path.join(process.resourcesPath, 'atom.asar', 'renderer', 'api', 'lib', 'ipc.js'))
|
||||||
|
|
||||||
it 'reads a normal file', ->
|
it 'reads a normal file', ->
|
||||||
file1 = path.join fixtures, 'asar', 'a.asar', 'file1'
|
file1 = path.join fixtures, 'asar', 'a.asar', 'file1'
|
||||||
assert.equal fs.readFileSync(file1).toString().trim(), 'file1'
|
assert.equal fs.readFileSync(file1).toString().trim(), 'file1'
|
||||||
|
|
Loading…
Reference in a new issue