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

Side by Side Diff: mojo/edk/system/channel_posix.cc

Issue 2065453004: Always leak the Mojo parent pipe handle on child process shutdown. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment Created 4 years, 6 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
« no previous file with comments | « mojo/edk/system/channel.h ('k') | mojo/edk/system/channel_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "mojo/edk/system/channel.h" 5 #include "mojo/edk/system/channel.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <sys/socket.h> 8 #include <sys/socket.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 } 130 }
131 } 131 }
132 if (write_error) { 132 if (write_error) {
133 // Do not synchronously invoke OnError(). Write() may have been called by 133 // Do not synchronously invoke OnError(). Write() may have been called by
134 // the delegate and we don't want to re-enter it. 134 // the delegate and we don't want to re-enter it.
135 io_task_runner_->PostTask(FROM_HERE, 135 io_task_runner_->PostTask(FROM_HERE,
136 base::Bind(&ChannelPosix::OnError, this)); 136 base::Bind(&ChannelPosix::OnError, this));
137 } 137 }
138 } 138 }
139 139
140 void LeakHandle() override {
141 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
142 leak_handle_ = true;
143 }
144
140 bool GetReadPlatformHandles( 145 bool GetReadPlatformHandles(
141 size_t num_handles, 146 size_t num_handles,
142 const void* extra_header, 147 const void* extra_header,
143 size_t extra_header_size, 148 size_t extra_header_size,
144 ScopedPlatformHandleVectorPtr* handles) override { 149 ScopedPlatformHandleVectorPtr* handles) override {
145 if (num_handles > std::numeric_limits<uint16_t>::max()) 150 if (num_handles > std::numeric_limits<uint16_t>::max())
146 return false; 151 return false;
147 #if defined(OS_MACOSX) && !defined(OS_IOS) 152 #if defined(OS_MACOSX) && !defined(OS_IOS)
148 // On OSX, we can have mach ports which are located in the extra header 153 // On OSX, we can have mach ports which are located in the extra header
149 // section. 154 // section.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 io_task_runner_->PostTask( 237 io_task_runner_->PostTask(
233 FROM_HERE, base::Bind(&ChannelPosix::WaitForWriteOnIOThread, this)); 238 FROM_HERE, base::Bind(&ChannelPosix::WaitForWriteOnIOThread, this));
234 } 239 }
235 } 240 }
236 241
237 void ShutDownOnIOThread() { 242 void ShutDownOnIOThread() {
238 base::MessageLoop::current()->RemoveDestructionObserver(this); 243 base::MessageLoop::current()->RemoveDestructionObserver(this);
239 244
240 read_watcher_.reset(); 245 read_watcher_.reset();
241 write_watcher_.reset(); 246 write_watcher_.reset();
247 if (leak_handle_)
248 ignore_result(handle_.release());
242 handle_.reset(); 249 handle_.reset();
243 #if defined(OS_MACOSX) 250 #if defined(OS_MACOSX)
244 handles_to_close_.reset(); 251 handles_to_close_.reset();
245 #endif 252 #endif
246 253
247 // May destroy the |this| if it was the last reference. 254 // May destroy the |this| if it was the last reference.
248 self_ = nullptr; 255 self_ = nullptr;
249 } 256 }
250 257
251 // base::MessageLoop::DestructionObserver: 258 // base::MessageLoop::DestructionObserver:
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 std::unique_ptr<base::MessageLoopForIO::FileDescriptorWatcher> write_watcher_; 489 std::unique_ptr<base::MessageLoopForIO::FileDescriptorWatcher> write_watcher_;
483 490
484 std::deque<PlatformHandle> incoming_platform_handles_; 491 std::deque<PlatformHandle> incoming_platform_handles_;
485 492
486 // Protects |pending_write_| and |outgoing_messages_|. 493 // Protects |pending_write_| and |outgoing_messages_|.
487 base::Lock write_lock_; 494 base::Lock write_lock_;
488 bool pending_write_ = false; 495 bool pending_write_ = false;
489 bool reject_writes_ = false; 496 bool reject_writes_ = false;
490 std::deque<MessageView> outgoing_messages_; 497 std::deque<MessageView> outgoing_messages_;
491 498
499 bool leak_handle_ = false;
500
492 #if defined(OS_MACOSX) 501 #if defined(OS_MACOSX)
493 base::Lock handles_to_close_lock_; 502 base::Lock handles_to_close_lock_;
494 ScopedPlatformHandleVectorPtr handles_to_close_; 503 ScopedPlatformHandleVectorPtr handles_to_close_;
495 #endif 504 #endif
496 505
497 DISALLOW_COPY_AND_ASSIGN(ChannelPosix); 506 DISALLOW_COPY_AND_ASSIGN(ChannelPosix);
498 }; 507 };
499 508
500 } // namespace 509 } // namespace
501 510
502 // static 511 // static
503 scoped_refptr<Channel> Channel::Create( 512 scoped_refptr<Channel> Channel::Create(
504 Delegate* delegate, 513 Delegate* delegate,
505 ScopedPlatformHandle platform_handle, 514 ScopedPlatformHandle platform_handle,
506 scoped_refptr<base::TaskRunner> io_task_runner) { 515 scoped_refptr<base::TaskRunner> io_task_runner) {
507 return new ChannelPosix(delegate, std::move(platform_handle), io_task_runner); 516 return new ChannelPosix(delegate, std::move(platform_handle), io_task_runner);
508 } 517 }
509 518
510 } // namespace edk 519 } // namespace edk
511 } // namespace mojo 520 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/channel.h ('k') | mojo/edk/system/channel_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698