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 <kwiberg@webrtc.org> Reviewed-by: Steve Anton <steveanton@webrtc.org> Cr-Commit-Position: refs/heads/master@{#27284}
This commit is contained in:
parent
2611164688
commit
12ba3adcaf
@ -3628,13 +3628,18 @@ void PeerConnection::SetBitrateAllocationStrategy(
|
||||
std::unique_ptr<rtc::BitrateAllocationStrategy>
|
||||
bitrate_allocation_strategy) {
|
||||
if (!worker_thread()->IsCurrent()) {
|
||||
rtc::BitrateAllocationStrategy* strategy_raw =
|
||||
bitrate_allocation_strategy.release();
|
||||
worker_thread()->Invoke<void>(RTC_FROM_HERE, [this, strategy_raw]() {
|
||||
RTC_DCHECK_RUN_ON(worker_thread());
|
||||
call_->SetBitrateAllocationStrategy(
|
||||
absl::WrapUnique<rtc::BitrateAllocationStrategy>(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<rtc::BitrateAllocationStrategy> strategy;
|
||||
void operator()() {
|
||||
RTC_DCHECK_RUN_ON(pc->worker_thread());
|
||||
pc->call_->SetBitrateAllocationStrategy(std::move(strategy));
|
||||
}
|
||||
};
|
||||
worker_thread()->Invoke<void>(
|
||||
RTC_FROM_HERE, Task{this, std::move(bitrate_allocation_strategy)});
|
||||
return;
|
||||
}
|
||||
RTC_DCHECK_RUN_ON(worker_thread());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user