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

Side by Side Diff: net/base/file_stream_context.cc

Issue 888143003: Fix a use after free crasher in the ReadAsync task initiated on Windows by the FileStream::Context:… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed trybot redness Created 5 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/base/file_stream_context.h" 5 #include "net/base/file_stream_context.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/profiler/scoped_tracker.h" 10 #include "base/profiler/scoped_tracker.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 return *this; 70 return *this;
71 } 71 }
72 72
73 // --------------------------------------------------------------------- 73 // ---------------------------------------------------------------------
74 74
75 void FileStream::Context::Orphan() { 75 void FileStream::Context::Orphan() {
76 DCHECK(!orphaned_); 76 DCHECK(!orphaned_);
77 77
78 orphaned_ = true; 78 orphaned_ = true;
79 79
80 #if defined(OS_WIN)
81 // Clean up weak pointers here to ensure that they are destroyed on the
82 // same thread where they were created.
83 weak_ptr_factory_.InvalidateWeakPtrs();
84 #endif
85
86 if (!async_in_progress_) { 80 if (!async_in_progress_) {
87 CloseAndDelete(); 81 CloseAndDelete();
88 } else if (file_.IsValid()) { 82 } else if (file_.IsValid()) {
89 #if defined(OS_WIN) 83 #if defined(OS_WIN)
90 CancelIo(file_.GetPlatformFile()); 84 CancelIo(file_.GetPlatformFile());
91 #endif 85 #endif
92 } 86 }
93 } 87 }
94 88
95 void FileStream::Context::Open(const base::FilePath& path, 89 void FileStream::Context::Open(const base::FilePath& path,
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 // should be reset before Close() because it shouldn't run if any async 240 // should be reset before Close() because it shouldn't run if any async
247 // operation is in progress. 241 // operation is in progress.
248 async_in_progress_ = false; 242 async_in_progress_ = false;
249 if (orphaned_) 243 if (orphaned_)
250 CloseAndDelete(); 244 CloseAndDelete();
251 else 245 else
252 callback.Run(result.result); 246 callback.Run(result.result);
253 } 247 }
254 248
255 } // namespace net 249 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698