From 12ba3adcafe669abfcb0fc7d67d28853ab47949a Mon Sep 17 00:00:00 2001 From: Karl Wiberg Date: Tue, 26 Mar 2019 11:18:39 +0100 Subject: [PATCH] Move unique_ptr into task instead of using a raw pointer The raw pointer would have leaked if the task was ever destroyed without being run. Bug: webrtc:9987 Change-Id: Iddeb1adf0f836b8fec3056eab89bce7b9f034ca7 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/128865 Commit-Queue: Karl Wiberg Reviewed-by: Steve Anton Cr-Commit-Position: refs/heads/master@{#27284} --- pc/peer_connection.cc | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc index 28cf957481..ec2f656422 100644 --- a/pc/peer_connection.cc +++ b/pc/peer_connection.cc @@ -3628,13 +3628,18 @@ void PeerConnection::SetBitrateAllocationStrategy( std::unique_ptr bitrate_allocation_strategy) { if (!worker_thread()->IsCurrent()) { - rtc::BitrateAllocationStrategy* strategy_raw = - bitrate_allocation_strategy.release(); - worker_thread()->Invoke(RTC_FROM_HERE, [this, strategy_raw]() { - RTC_DCHECK_RUN_ON(worker_thread()); - call_->SetBitrateAllocationStrategy( - absl::WrapUnique(strategy_raw)); - }); + // TODO(kwiberg): Use a lambda instead when C++14 makes it possible to + // move-capture values in lambdas. + struct Task { + PeerConnection* const pc; + std::unique_ptr strategy; + void operator()() { + RTC_DCHECK_RUN_ON(pc->worker_thread()); + pc->call_->SetBitrateAllocationStrategy(std::move(strategy)); + } + }; + worker_thread()->Invoke( + RTC_FROM_HERE, Task{this, std::move(bitrate_allocation_strategy)}); return; } RTC_DCHECK_RUN_ON(worker_thread());