From 7c2e958711aaa17fc03b937bf0657230e7bb1dde Mon Sep 17 00:00:00 2001 From: Tomas Gunnarsson Date: Fri, 25 Feb 2022 23:36:24 +0100 Subject: [PATCH] Add a guard against double delete to Connection::Destroy Bug: webrtc:13752 Change-Id: I80345fe2e560773f9f98f850def386ec53ae798f Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/252660 Reviewed-by: Taylor Brandstetter Commit-Queue: Tomas Gunnarsson Cr-Commit-Position: refs/heads/main@{#36085} --- p2p/base/connection.cc | 5 +++++ p2p/base/connection.h | 3 +++ 2 files changed, 8 insertions(+) diff --git a/p2p/base/connection.cc b/p2p/base/connection.cc index a04f318acb..1d674e2bcb 100644 --- a/p2p/base/connection.cc +++ b/p2p/base/connection.cc @@ -834,6 +834,11 @@ void Connection::Prune() { void Connection::Destroy() { RTC_DCHECK_RUN_ON(network_thread_); + if (pending_delete_) + return; + + pending_delete_ = true; + RTC_DLOG(LS_VERBOSE) << ToString() << ": Connection destroyed"; // Fire the 'destroyed' event before deleting the object. This is done diff --git a/p2p/base/connection.h b/p2p/base/connection.h index 8254706318..a7b3490757 100644 --- a/p2p/base/connection.h +++ b/p2p/base/connection.h @@ -366,6 +366,9 @@ class Connection : public CandidatePairInterface, public sigslot::has_slots<> { rtc::RateTracker recv_rate_tracker_; rtc::RateTracker send_rate_tracker_; int64_t last_send_data_ = 0; + // Set to true when deletion has been scheduled and must not be done again. + // See `Destroy()` for more details. + bool pending_delete_ RTC_GUARDED_BY(network_thread_) = false; private: // Update the local candidate based on the mapped address attribute.