Jelajahi Sumber

2010-04-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Ensure that std::ofstream is destroyed before renaming.
	* src/SessionSerializer.cc
	* src/util.cc
Tatsuhiro Tsujikawa 15 tahun lalu
induk
melakukan
aa08af9928
3 mengubah file dengan 26 tambahan dan 16 penghapusan
  1. 6 0
      ChangeLog
  2. 10 8
      src/SessionSerializer.cc
  3. 10 8
      src/util.cc

+ 6 - 0
ChangeLog

@@ -1,3 +1,9 @@
+2010-04-14  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Ensure that std::ofstream is destroyed before renaming.
+	* src/SessionSerializer.cc
+	* src/util.cc
+
 2010-04-13  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Fixed the bug that user specified path is escaped using

+ 10 - 8
src/SessionSerializer.cc

@@ -62,14 +62,16 @@ SessionSerializer::SessionSerializer
 bool SessionSerializer::save(const std::string& filename) const
 {
   std::string tempFilename = strconcat(filename, "__temp");
-  std::ofstream out(tempFilename.c_str(), std::ios::binary);
-  if(!out) {
-    return false;
-  }
-  save(out);
-  out.flush();
-  if(!out) {
-    return false;
+  {
+    std::ofstream out(tempFilename.c_str(), std::ios::binary);
+    if(!out) {
+      return false;
+    }
+    save(out);
+    out.flush();
+    if(!out) {
+      return false;
+    }
   }
   return File(tempFilename).renameTo(filename);
 }

+ 10 - 8
src/util.cc

@@ -1147,14 +1147,16 @@ bool saveAs
     return false;
   }
   std::string tempFilename = strconcat(filename, "__temp");
-  std::ofstream out(tempFilename.c_str(), std::ios::binary);
-  if(!out) {
-    return false;
-  }
-  out << data;
-  out.flush();
-  if(!out) {
-    return false;
+  {
+    std::ofstream out(tempFilename.c_str(), std::ios::binary);
+    if(!out) {
+      return false;
+    }
+    out << data;
+    out.flush();
+    if(!out) {
+      return false;
+    }
   }
   return File(tempFilename).renameTo(filename);
 }