Index: base/threading/thread.cc |
diff --git a/base/threading/thread.cc b/base/threading/thread.cc |
index 6ca1caea099d344fa5c44cebd7310bd5c7078777..7bff24232e2bf2d66fda4485a4246ebae2e98332 100644 |
--- a/base/threading/thread.cc |
+++ b/base/threading/thread.cc |
@@ -94,8 +94,9 @@ bool Thread::StartWithOptions(const Options& options) { |
type = MessageLoop::TYPE_CUSTOM; |
message_loop_timer_slack_ = options.timer_slack; |
- message_loop_ = new MessageLoop(type, options.message_pump_factory); |
- |
+ scoped_ptr<MessageLoop> message_loop = MessageLoop::CreateUnbound( |
+ type, options.message_pump_factory); |
+ message_loop_ = message_loop.get(); |
start_event_.reset(new WaitableEvent(false, false)); |
// Hold the thread_lock_ while starting a new thread, so that we can make sure |
@@ -111,13 +112,16 @@ bool Thread::StartWithOptions(const Options& options) { |
} |
if (!created) { |
DLOG(ERROR) << "failed to create thread"; |
- delete message_loop_; |
message_loop_ = nullptr; |
start_event_.reset(); |
return false; |
} |
} |
+ // The ownership of message_loop is managemed by the newly created thread |
+ // within the ThreadMain. |
+ ignore_result(message_loop.release()); |
+ |
DCHECK(message_loop_); |
return true; |
} |