]> khamidou — GitHub mirrors - electron.git/commitdiff
win: Fix leaking of fd when reading file in asar
authorCheng Zhao <zcbenz@gmail.com>
Thu, 24 Sep 2015 04:11:07 +0000 (12:11 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 24 Sep 2015 04:11:07 +0000 (12:11 +0800)
atom/common/asar/archive.cc
atom/common/asar/archive.h

index 0b2f59ae0f18e9c5104d98bf7ca5069f58884491..969f958956cae474e6c0b9b32ac8c15cb8e90809 100644 (file)
@@ -115,6 +115,14 @@ bool FillFileInfoWithNode(Archive::FileInfo* info,
 Archive::Archive(const base::FilePath& path)
     : path_(path),
       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) {
 }
 
@@ -271,17 +279,7 @@ bool Archive::CopyFileOut(const base::FilePath& path, base::FilePath* out) {
 }
 
 int Archive::GetFD() const {
-  if (!file_.IsValid())
-    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
+  return fd_;
 }
 
 }  // namespace asar
index dda7aa78e0c0957d157b41847c4978ee729187dd..f2ff2f76d6761c02a885f5f95cf76e5fe66a87a8 100644 (file)
@@ -69,6 +69,7 @@ class Archive {
  private:
   base::FilePath path_;
   base::File file_;
+  int fd_;
   uint32 header_size_;
   scoped_ptr<base::DictionaryValue> header_;