diff --git a/ChangeLog b/ChangeLog index 3fc4b7f3..6e8ce7c7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-04-14 Tatsuhiro Tsujikawa + + Ensure that std::ofstream is destroyed before renaming. + * src/SessionSerializer.cc + * src/util.cc + 2010-04-13 Tatsuhiro Tsujikawa Fixed the bug that user specified path is escaped using diff --git a/src/SessionSerializer.cc b/src/SessionSerializer.cc index 45db0e15..5e1a1c9d 100644 --- a/src/SessionSerializer.cc +++ b/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); } diff --git a/src/util.cc b/src/util.cc index 3ad1b22b..58a37d4a 100644 --- a/src/util.cc +++ b/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); }