Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(934)

Unified Diff: base/files/file_util_win.cc

Issue 2687713003: Stop base::OpenFile from leaking fds/handles into child procs. (Closed)
Patch Set: gab comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/files/file_util_unittest.cc ('k') | build/sanitizers/lsan_suppressions.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/files/file_util_win.cc
diff --git a/base/files/file_util_win.cc b/base/files/file_util_win.cc
index 9cb446bc87ce581cdb7088551c72ec0d134d2334..65dc5ce1e2fe7495624cc6d8c16b954395eb11ac 100644
--- a/base/files/file_util_win.cc
+++ b/base/files/file_util_win.cc
@@ -70,6 +70,14 @@ bool DeleteFileRecursive(const FilePath& path,
return true;
}
+// Appends |mode_char| to |mode| before the optional character set encoding; see
+// https://msdn.microsoft.com/library/yeby3zcb.aspx for details.
+void AppendModeCharacter(base::char16 mode_char, base::string16* mode) {
+ size_t comma_pos = mode->find(L',');
+ mode->insert(comma_pos == base::string16::npos ? mode->length() : comma_pos,
+ 1, mode_char);
+}
+
} // namespace
FilePath MakeAbsoluteFilePath(const FilePath& input) {
@@ -594,8 +602,14 @@ bool GetFileInfo(const FilePath& file_path, File::Info* results) {
}
FILE* OpenFile(const FilePath& filename, const char* mode) {
+ // 'N' is unconditionally added below, so be sure there is not one already
+ // present before a comma in |mode|.
+ DCHECK(
+ strchr(mode, 'N') == nullptr ||
+ (strchr(mode, ',') != nullptr && strchr(mode, 'N') > strchr(mode, ',')));
ThreadRestrictions::AssertIOAllowed();
string16 w_mode = ASCIIToUTF16(mode);
+ AppendModeCharacter(L'N', &w_mode);
return _wfsopen(filename.value().c_str(), w_mode.c_str(), _SH_DENYNO);
}
« no previous file with comments | « base/files/file_util_unittest.cc ('k') | build/sanitizers/lsan_suppressions.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698