]> 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 06:00:53 +0000 (14:00 +0800)
atom/common/asar/archive.cc
atom/common/asar/archive.h

index be99530c9c985527cd23ebbbd06e44da371a3728..91bdfd7ba3b34d5346168617da4156d97fd90553 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) {
 }
 
@@ -269,17 +277,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 2acd17fd7ab4a34dc9c9aa869da80a4bac070870..068858f77409d732c7c8f9cf1260d1b67d16e3bf 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_;